+ 1

c++ variable declaration

int a, b; is it always the address of a < the address of b (&a < &b) or it depends on the compiler?

26th Jun 2021, 5:07 PM
Alpha Zero
Alpha Zero - avatar
7 odpowiedzi
+ 6
Martin Taylor The memory addresses thats assigned to variable is not during compile time. its done by os. seems like you are talking about relative addressing while i am saying about absolute addressing in virtual memory have a look at this . https://stackoverflow.com/questions/48969644/is-the-address-of-a-variable-in-c-the-real-address-in-the-ram-of-the-computer/48970674
26th Jun 2021, 7:00 PM
Prashanth Kumar
Prashanth Kumar - avatar
+ 4
thank you Martin Taylor for correcting me :) really well explained. Initially i said that because i tested a piece of code simple one like this int v; printf("%d",&v); compiling this thing on windows always gives a particular value . no matter when its ran . which means addresses are compiler generated .. but then i compiled same piece for linux , it always gave random values on each ram . so i thought that its decided by os . now i get it that the relative positioning of it wont change . Thank you very much for clearing the ambiguity .
27th Jun 2021, 3:55 AM
Prashanth Kumar
Prashanth Kumar - avatar
+ 3
its not necessary for the declaration to have accupied successive blocks. its more dependent of os rather than compiler to allocate memory . and for arrays its guranteed that memory is contagious but thats not the case for variables .
26th Jun 2021, 5:16 PM
Prashanth Kumar
Prashanth Kumar - avatar