|
-
August 1st, 2011, 12:58 AM
#1
variables addreses
Please look at this code:
int main()
{
int a=5;
int b;
int *c=new int(5);
cout<<&a<<endl; //0012FED4
cout<<&b<<endl; //0012FEC8
cout<<&c<<endl; //0012FEBC
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<<endl; //00456014
cout<<&b<<endl; //00456018
cout<<&c<<endl; //004576A0
cout<<&d<<endl; //004576A4
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|