What are different format specifiers used in C language?


Format specifiers are used for input-output (I/O) operations. With the help of a format specifier, the compiler can understand what type of data is in I/O operation.

There are some elements that affect the format specifier. They are as follows −

  • A minus symbol (-): Left alignment.

  • The number after % specifies the minimum field width. If the string is less than the width, it will be filled with spaces.

  • Period (.) − Separate field width and precision.

Format specifiers

Here is the list of some format specifiers −

SpecifierUsed for
%ca single character
%sa string
%hishort (signed)
%hushort (unsigned)
%Lflong double
%nprints nothing
%da decimal integer (assumes base 10)
%ia decimal integer (detects the base automatically)
%oan octal (base 8) integer
%xa hexadecimal (base 16) integer
%pan address (or pointer)
%fa floating point number for floats
%uint unsigned decimal
%ea floating point number in scientific notation
%Ea floating point number in scientific notation
%%the % symbol

Example

Given below is the C program for %o octal integer format specifier −

 Live Demo

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

Output

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

37

Updated on: 08-Mar-2021

519 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements