Home  >  Article  >  Backend Development  >  What is the difference between %p and %x in C/C++?

What is the difference between %p and %x in C/C++?

WBOY
WBOYforward
2023-08-27 14:57:071300browse

What is the difference between %p and %x in C/C++?

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

Example

#include<stdio.h>
main() {
   int x = 59;
   printf("Value using %%p: %p\n", x);
   printf("Value using %%x: %x\n", x);
}

Output

Value using %p: 000000000000003B
Value using %x: 3b

The above is the detailed content of What is the difference between %p and %x in C/C++?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete