Format specifiers define the type of data that will be printed on standard output. Whether you’re printing formatted output with printf() or accepting input with scanf(), format specifiers are required.

C format specifiers cover the various data formats of variables read with the scanf() function to read data and printed with the printf() function. There are several data formats for data types such as char, string, int, float, double, long, short, long int, short int, unsigned, octal, hexadecimal, and so on in the list of format specifiers in C. The scanf() and printf() functions in C are used to format data using format specifiers.

There are many format specifiers in C. Multiple format specifiers can be used to print a variable with a data type. An integer variable, for example, can be printed as a decimal number, an octagonal number, or a hexadecimal number.

List of Format Specifiers in C

The following example illustrates how to print a variable with different format specifiers.

#include <stdio.h>

int main(int argc, char** argv) {
	int a = 15;
	float b = 12345.12345;
	printf("int value   : %d\n", a); 
	printf("oct value   : %o\n", a); 
	printf("hex value   : %x\n", a); 
	printf("hex value   : %X\n\n", a); 
	printf("float value : %f\n", b); 
	printf("float value : %e\n", b); 
	printf("float value : %E\n", b); 
	printf("float value : %G\n", b); 
	return 0;


int value   : 15
oct value   : 17
hex value   : f
hex value   : F

float value : 12345.123047
float value : 1.234512e+004
float value : 1.234512E+004
float value : 12345.1

Table – Format Specifiers

The table below lists all format specifiers that are provided in C

Sr. No. Data Type Format
1 char %c
2 string %s
3 int %d
4 float %f
5 octal  int %o
6 hexadecimal int lowercase %x
7 hexadecimal int uppercase %X
8 unsigned int %u
9 short int %hd
10 unsigned short int %hu
11 long int %ld
12 unsigned long int %lu
13 long long int %lld
14 unsigned long long int %llu
15 double %lf
16 long double %LF
17 float scientific notation lowercase %e
18 float scientific notation uppercase %E
19 float or double scientific notation lowercase %g
20 float or double scientific notation uppercase %G
21 signed int %i
22 signed short int %hi
23 signed long int %li
24 Address of the pointer void* %p
25 Print nothing %n
26 Print % %%

Leave a Reply