List of Format Specifiers in C

C Language has many format specifiers. A variable with a data type can be printed using different format specifiers. For example, a integer variable can be printed as decimal number, octagonal number and 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;
}

Output

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

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

Sr. No.Data TypeFormat
1char%c
2string%s
3int%d
4float%f
5 octal  int%o
6hexadecimal int lowercase%x
7 hexadecimal int uppercase %X
8unsigned int%u
9short int%hd
10unsigned short int%hu
11long int%ld
12unsigned long int%lu
13long long int%lld
14unsigned long long int%llu
15double%lf
16long 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
21signed int%i
22signed short int%hi
23signed long int%li
24Address of the pointer void*%p
25Print nothing %n
26Print %%%



Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *