I just write a simple program to print the address of variable.
#include <stdio.h>
void main(){
int *a;
int b;
b=5;
a=&b;
printf("\n*a is the value of the integer: %d\n",*a);
printf("&a is the address of variable a: %p\n", &a);
printf(" a is the address stored in a: %p\n",a);
printf("&b is the address of variable b: %p\n\n",&b);
}
The result is:
*a is the value of the integer: 5
&a is the address of variable a: 0x7fff935ad2b0
a is the address stored in a: 0x7fff935ad2bc
&b is the address of variable b: 0x7fff935ad2bc
Why the addresses printed are not in the standard form?
Sorry for the silly question, but I just don’t understand.
EDIT
I have another program
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct small{
int a;
};
int main(){
struct small *sm;
sm = malloc(sizeof(struct small));
memset(sm,0,sizeof(struct small));
sm->a = 5;
printf("The address of sm is: %p\n", &sm);
printf("The address stored in sm is: %p\n", sm);
return 0;
}
The output is:
The address of sm is: 0x7fffd1363158
The address stored in sm is: 0x17a3010
So I expected the format 0x17a3010 is somewhat standard to me.
And again why in this case the format of %p is different?
That is called hexadecimal, i.e., base-16. It makes it easier to view groups of bits as bytes than binary or base-10 would. I’m not sure I understand your question. There is no “standard form”, but if there were one this would be it.
Per your edit:
Those two are exactly the same.
0x17a3010is no different than0x00000000017a3010.