Local variables adresses in C

c, memory-management

Solution

The storage space for a local variable is on the stack. The X86 processor family has a stack which "grows downward". This means that as allocations occur (for example assigning a variable), the stack pointer is moved downwards toward lower memory addresses.

`&a` is greater than `&b` because after `&a` was assigned, the stack pointer was moved downward to a lower address for the next allocation.

Problem

I have this little Program: ``` #import <stdio.h> #import <stdlib.h> void main(void) { char a; char b; printf("Adress a: %p\n", (void *)&a); printf("Adress b: %p\n", (void *)&b); return 0; } ``` The adress of b is lower, than the adress of b. Why is it like this? Or am i doing something wrong?

Original source