Data section in a.out
#include <stdio.h>int main(){return 0;}
It gives
text data bss dec hex filename 960 248 8 1216 4c0 a.out
when you do
int a;int main(){ char *p = "hello"; return 0;}
it gives
text data bss dec hex filename 982 248 8 1238 4d6 a.out
at that time hello is stored in .rodata
and the location of that address is stored in char pointer p
but here p is stored on stack
and size doesnt shows stack. And i am not sure but .rodata is here calculated in text or dec.
when you write
int a;char *p = "hello";int main(){ return 0;}
it gives
text data bss dec hex filename 966 252 8 1226 4ca a.out
now here again "hello" is stored in .rodata but char pointer takes 4 byte and stored in data so data is increment by 4
For more info http://codingfreak.blogspot.in/2012/03/memory-layout-of-c-program-part-2.html
Actually, that's an implementation detail. The compiler works by an as-is principle. Meaning that as long as the behavior of the program is the same, it's free to exclude any piece of code it wants. In this case, it can skip char* p = "hello"
altogether.