?
2011-07-31 23:02:16 UTC
int main()
{
int a=5;
int b;
int *c=new int(5);
cout<<&a<
return 0;
}
As you can see there is 12 bytes space between every address.
Now look at this:
int a=5;
int b=8;
int c;
int *d=new int(5);
int main()
{
cout<<&a<
return 0;
}
Between Variable (a) and (b) is 4 bytes space but for (c) its different. There is approximately 6000 bytes space. What’s the point of this?
I’ve learnt that initialized variable is stored in .data section, uninitialized variables in .bss and pointers in heap. But here I am really confused. Why addresses in code one is contiguous with 12 bytes spaces. Why 12? If integer is 4 bytes! What is this extra 8 bytes?
And why uninitialized variable is close to a pointer variable that is supposed to be in heap section.
Why base address for variables inside main function is 0012FED4 but for second code its 00456014.
Please someone write me a line about this issue.
Thanks for any advance.