Format Specifiers in C

The format specifier in C is used to tell the compiler about the type of data to be printed or scanned in input and output operations.
The below table contains the most commonly used format specifiers in C:
Format Specifier | Description |
---|---|
%c | For character type. |
%d | For signed integer type. |
%e or %E | For scientific notation of floats. |
%f | For float type. |
%g or %G | For float type with the current precision. |
%i | signed integer |
%ld or %li | Long |
%lf | Double |
%Lf | Long double |
%lu | Unsigned int or unsigned long |
%lli or %lld | Long long |
%llu | Unsigned long long |
%o | Octal representation |
%p | Pointer |
%s | String |
%u | Unsigned int |
%x or %X | Hexadecimal representation |
%n | Prints nothing |
%% | Prints % character |
Symbol/ Notation |
Format Specifier Name |
Description |
Data type |
Range |
Size |
%d or %i |
Decimal integer |
Signed integer in base 10 |
int |
-2147483648 to 2147483647 |
4 bytes |
%f |
Float |
Floating point number with six digits of precision |
float |
1.2E-38 to 3.4E+38 |
4 bytes |
%Lf |
Long double |
Floating point number with extended precision |
long double |
3.4E-4932 to 1.1E+4932 |
10 or 16 bytes |
%c |
Character |
Single character |
char |
-128 to 127 |
1 byte |
%s |
String |
String of characters |
char[] |
- |
- |
%p |
Pointer |
Address in memory |
void * |
- |
4 or 8 bytes |
%Id |
Long integer |
Signed long integer |
signed long |
-2147483648 to 2147483647 |
4 bytes |
%lu |
Unsigned Long |
Unsigned long integer |
unsigned long |
0 to 4294967295 |
4 bytes |
%lld |
Long Long |
Signed long long integer |
long long |
-9223372036854775808 to 9223372036854775807 |
8 bytes |
%llu |
Unsigned Long Long |
Unsigned long long integer |
unsigned long long |
0 to 18446744073709551615 |
8 bytes |
%x |
Hexadecimal |
Unsigned integer in base 16 |
unsigned int |
0 to 4294967295 |
4 bytes |
%E |
Scientific notation |
Floating point number in scientific notation |
double |
2.2E-308 to 1.8E+308 |
8 bytes |
%o |
Octal |
Unsigned integer in base 8 |
unsigned int |
0 to 4294967295 |
4 bytes |
%u |
Unsigned Decimal |
Unsigned integer in base 10 |
unsigned int |
0 to 4294967295 |
4 bytes |
%hd |
Short |
Short signed integer |
short |
-32768 to 32767 |
2 bytes |
%m |
Error message |
Error message corresponding to the error number in the argument |
int |
- |
- |
%n |
Output assignment |
Stores the number of characters written so far into the pointer argument |
int * |
- |
- |
%hu |
Unsigned Short |
Short unsigned integer |
unsigned short |
0 to 65535 |
2 bytes |