format specifiers in c
%d
: Integer format specifier
- Used for formatting and printing integers.
%f
: Float format specifier
- Used for formatting and printing floating-point numbers.
%c
: Character format specifier
- Used for formatting and printing characters.
%s
: String format specifier
- Used for formatting and printing strings.
%p
: Pointer format specifier
- Used for formatting and printing memory addresses.
%x
or %X
: Hexadecimal format specifier
- Used for formatting and printing integers in hexadecimal (lowercase or uppercase).
%o
: Octal format specifier
- Used for formatting and printing integers in octal.
%u
: Unsigned Integer format specifier
- Used for formatting and printing unsigned integers.
%e
or %E
: Scientific notation format specifier
- Used for formatting and printing floating-point numbers in scientific notation.
%g
or %G
: Compact format specifier
- Used for formatting and printing floating-point numbers in either decimal or scientific notation, depending on the value.
%a
or %A
: Hexadecimal floating-point format specifier
- Used for formatting and printing floating-point numbers in hexadecimal.
%ld
or %lu
: Long Integer format specifier
- Used for formatting and printing long integers (signed or unsigned).
%lld
or %llu
: Long Long Integer format specifier
- Used for formatting and printing long long integers (signed or unsigned).
%hd
or %hu
: Short Integer format specifier
- Used for formatting and printing short integers (signed or unsigned).
%Lf
: Long Double format specifier
- Used for formatting and printing long double floating-point numbers.
%Lf
: Long Double format specifier (alternative)
- Some compilers may use %Lf
instead of %Lf
for long double format.
%n
: Number of characters written so far format specifier
- Used for obtaining the number of characters written by the printf function.
Note: The explanations provided here are concise and may not cover all nuances. Refer to the C standard or documentation for a comprehensive understanding of format specifiers.