Home  >  Article  >  Backend Development  >  What are the different format specifiers used in C language?

What are the different format specifiers used in C language?

王林
王林forward
2023-08-26 18:33:151361browse

What are the different format specifiers used in C language?

Format specifiers are used for input and output (I/O) operations. Through format specifiers, the compiler can understand the data types used in I/O operations.

There are some elements that affect format specifiers. They are as follows:

  • Minus sign (-): Left aligned. The number after

  • % specifies the minimum field width. If the string length is less than the width, it will be padded with spaces.

  • Period (.): Separates field width and precision.

Format Specifiers

The following is a list of some format specifiers:

##%cSingle character%sString##%hi%hu%Lf%n%d%i%o%x%p%f%u%e%E%%Example
Specifiers Use
Short integer (signed)
Short (unsigned)
Long double floating point number
Do not print anything
Decimal integer (default is decimal)
Decimal integer (automatically detect base)
Octal integer
Hexadecimal integer
Address (or pointer)
Floating point number
Unsigned decimal integer
Scientific notation The floating point number represented by
The floating point number represented by scientific notation
Percent sign

The following is an example of a C program using the %o octal integer format specifier:

Demonstration

#include <stdio.h>
int main() {
   int num = 31;
   printf("%o</p><p>", num);
   return 0;
}

Output

When the above program is executed, it produces the following result −

37

The above is the detailed content of What are the different format specifiers used in C language?. 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