I thought the memory address of variable become bigger and bigger, until I tried this code :
#include <stdio.h>
int main()
{
int IamfirstVariable = 9;
char array1[10] = {'0','1','2','3','4','5','6','7','8','9'};
char array2[10] = {'0','1','2','3','4','5','6','7','8','9'};
char IamLastVariable = '0';
printf("variable start :%p\n",&IamfirstVariable);
printf("array1 address start :%p end : %p \n",&array1[0],&array1[9]);
printf("array2 address start :%p end : %p \n",&array2[0],&array2[9]);
printf("variable end :%p\n",&IamLastVariable);
return 0;
}
Output:
variable start :0xbfb02c3c
array1 address start :0xbfb02c32 end : 0xbfb02c3b
array2 address start :0xbfb02c28 end : 0xbfb02c31
variable end :0xbfb02c27
I am stucked by this . It seems that the last declared variable get the smallest address!
Can anyone explain this for me ?
----------------------EDIT----------------------------------------
I read the links in answer and got anohter question:
Since the stack glow downaward , why the address of array still glow upward ?