Same memory space being allocated again & again
- by shadyabhi
In each loop iteration, variable j is declared again and again. Then why is its address remaining same?
Shouldn't it be given some random address each time?
Is this compiler dependent?
#include<stdio.h>
#include<malloc.h>
int main()
{
int i=3;
while (i--)
{
int j;
printf("%p\n", &j);
}
return 0;
}
Testrun:-
shadyabhi@shadyabhi-desktop:~/c$ gcc test.c
shadyabhi@shadyabhi-desktop:~/c$ ./a.out
0x7fffc0b8e138
0x7fffc0b8e138
0x7fffc0b8e138
shadyabhi@shadyabhi-desktop:~/c$