%p format specifier in C

%p format specifier prints the values in hexadecimal form. The C standards says that the characters printed are implenation-defined, but in practice most C library implementation generate a sequence of hexadecimal digits

EX:

include<stdio.h>

int main() {
    int a = 4;
    printf("%d", a);// output is 4
    printf("%p", a);// output is   //0000000000000004
    return 0;
} 

Another EX:

include<stdio.h>

int main() {
    int a = 55;
    printf("%d", a);//output is 55
    printf("%p", a);//output is //0000000000000055
    return 0;
} 

Because 85 in decimal = 55 in hex

Note : output may differ on Compiler something like 0x4 and 0x55

Posted on by