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

What are the different format specifiers used in C language?

王林
Release: 2023-08-26 18:33:15
forward
1377 people have browsed it

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

Output

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

37
Copy after login

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!

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