I am trying to find the address location in C of a specific variable now I try to write a code which is this :
#include<stdio.h>
int main()
{
int g = 3;
printf("%p %d %u ",&g,&g,&g);
return 0;
}
now I am confused that why is GCC compiler is giving me warning using these :
Warnings are
warning: format '%d' expects type 'int', but argument 3 has type 'int *'
warning: format '%u' expects type 'unsigned int', but argument 4 has type 'int *'
Also the answers are quite amazing
0xbfa5953c -1079667396 3215299900
Now my question is which would I accept as a location to my number
The expression
&gevaluates to the same value (bitwise) in every case. It’s just a matter of how those bits should be interpreted.So it turns out that 0xbfa5953c (hex) == 3215299900 (dec), which is hardly surprising. The negative value is meaningless because a memory address is not a signed integer.