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 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 % | %% |