#include <stdio.h>
int main()
{
int *ptr;
int a=2;
ptr=&a;
printf("%p\n",ptr);
printf("%d\n",ptr);
printf("%p\n",a);
return 0;
}
The output I get is:
% ./a.out
0x7ffe12032c40
302197824
0x2
%
The value of the first two output changes (obviously because of ASLR) and the 0x2 remains constant.
The size of pointer isn't equal size of int, So you can't use %d instead of %p, %p is used for printing value stored in pointer variable, also using %p with int variable is undefined behavior (if you're on system which pointer and int have same size you may see correct result, but as C standard its an undefined behavior )
sizeof int is defined by compiler, different compilers may have different size of int on single machine, but pointer size is defined by machine type (8,16,32,64 bit)