Home > Backend Development > C++ > body text

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

WBOY
Release: 2023-08-27 14:57:07
forward
1294 people have browsed it

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);
}
Copy after login

Output

Value using %p: 000000000000003B
Value using %x: 3b
Copy after login

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!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template