why does the hexadecimal value of pointer address returned is always in decreasing order?
for example here int a
was declared before int d
, so it's address always comes out to be greater than d
, and same for &b
,&e
and &c
,&f
, I want to know that is this a fixed behavior or is this compiler dependent?
I am using gcc version 4.4.5 (Ubuntu/Linaro 4.4.4-1
)
#include<stdio.h>
int main(void){
int a=1;
int d=1;
char b='a' ;
char e='a';
float c=1.0;
float f=1.0;
printf("a=%p\nd=%p\nb=%p\ne=%p\nc=%p\nf=%p\n",&a,&d,&b,&e,&c,&f);
if (&a>&d)
printf("&a>&d\n");
else
{printf("&a<&d");
}
if (&a>&d && &b>&e && &c>&f)
printf("addresses are in descending order");
else{
printf("false");
}
return 0;
}
output:
a=0xbfc6bd98 //a>d
d=0xbfc6bd94
b=0xbfc6bd9f //b>e
e=0xbfc6bd9e
c=0xbfc6bd90 //c>f
f=0xbfc6bd8c
&a>&d
addresses are in descending order
PS: I am new to c