Home  >  Article  >  Backend Development  >  What do %x and %o mean in C language?

What do %x and %o mean in C language?

下次还敢
下次还敢Original
2024-05-02 19:48:331164browse

%x and %o in C language

In C language, "%x" and "%o" are format specifiers used in format strings. Used to specify how to print integers:

  • %x: Print an unsigned hexadecimal integer.
  • %o: Print an unsigned octal integer.

Usage:

To print an integer in hexadecimal or octal format, you need to use formatting functions such as printf() or sprintf() . The format specifier is placed before the variable to be printed. For example:

<code class="c">int number = 123;
printf("十六进制:%x\n", number);
printf("八进制:%o\n", number);</code>

Output:

Running the above code will output:

<code>十六进制:7b
八进制:173</code>

Note:

  • Unsigned integers are represented as non-negative numbers.
  • Hexadecimal numbers are represented using 0-9 and a-f (or A-F).
  • Octal numbers are represented using 0-7.

The above is the detailed content of What do %x and %o mean in C language?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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