>is there a portable way to write code to get the size that this
>code(with data) takes in memory ?
No.
The amount of memory that the code takes may vary at runtime, either
due to direct calls to malloc() or library use of it (For example,
it's possible the library will not allocate a buffer for stdout
until the program outputs something. Or the library allocates
buffers for every file open simultaneously, which can vary with
user input). The program's memory use may vary heavily with such
things as the quantity of input.
The amount of memory taken by shared libraries (which may be used
whether or not the program or even the compiler command line
specifically mentions them) will vary with the version of the library
and the platform.
In typical implementations the amount of memory taken by argv[] and
the argument strings will vary depending on the command that invoked
it. A similar issue exists with environment variables, which are
typically (but the standard doesn't require it) stored somewhere
in memory.
The amount of memory taken by automatic variables will vary with
the execution path, especially in recursive programs where the
recursion depth depends on user input.
Some linkers allow options which may affect the memory size of the
program, such as the size of a fixed stack. Other systems grow the
stack as needed.