Difference between %p and %x in C/C++

CC++Server Side ProgrammingProgramming

Here we will see what are the differences between %p and %x in C or C++. The %p is used to print the pointer value, and %x is used to print hexadecimal values. Though pointers can also be displayed using %u, or %x. If we want to print some value using %p and %x then we will not feel any major differences. The only difference that can be noticed is that the %p will print some leading zeros, but %x doesn’t.


main() {
   int x = 59;
   printf("Value using %%p: %p\n", x);
   printf("Value using %%x: %x\n", x);


Value using %p: 000000000000003B
Value using %x: 3b
Published on 02-May-2019 11:53:09