Facebook Page Twitter Page LinkedIn Page
× C Tutorial C Resources


The format specifiers helps the compiler to understand the data types and formats in the input or output stream. It is used with scanf() function while taking input and printf() function while printing the output. Here is the list of format specifiers available C language:

Format Specifier

SpecifierOutput
%d or %i Signed decimal integer
%u Unsigned decimal integer
%f or %F Decimal floating point
%e Scientific notation, lowercase like 8.7895e+3
%E Scientific notation, uppercase like 8.7895E+3
%g Similar as %e or %f
%G Similar as %E or %F
%c Character
%s String of characters
%p Pointer address
%o Unsigned octal
%x Unsigned hexadecimal integer
%X Unsigned hexadecimal integer (uppercase)
%a Hexadecimal floating point, lowercase
%A Hexadecimal floating point, uppercase
%n Prints nothing
%% Prints % character

Example:

The below example shows how to use different format specifier in C.

#include <stdio.h>
int factorial(int x); 

int main (){
  int i = 10;
  printf("%i\n", i);
  printf("%d\n", i);

  float j = 10.5;
  printf("%f\n", j);
  printf("%.3f\n", j); //specify precision
  printf("%e\n", j);   //prints in scientific notation

  int* p = &k;
  printf("%p\n", p);   //prints pointer

  int k = 250;
  printf("%o\n", k);   //prints in octal format
  printf("%x\n", k);   //prints in hexadecimal format

  return 0;
}

The output of the above code will be:

10
10

10.500000
10.500
1.050000e+01

0x7fff98a057cc

372
fa