When I write:
int a;
int c;
OR
int a, c;
- When are
aandcstored in adjacent places in the memory? ((&a+1)equals&c?) - Does the way you define them has influence on this? Or it only depends on the machine?
No, you cannot guarantee that a and c are in adjacent places in memory, but that is usually the case. I believe usually &a - 1 will be equal to &c as the stack usually grows downwards.
If you want contiguous variables then use an array.
Does the way you define them has influence on this?
Usually the compiler won't reorder unless it has to. For instance to meet certain alignments or for performance reasons.
Also, as Mysticial says, the compiler can sometimes optimize variables out so they never exist in memory at all.
array do so.. I was just wondering if it happens when I declare two ints like I did. Regarding the optimization, when would the compiler do such a thing?