C Format Specifier in C Language
Categories: C language
The Format specifier is a string used in the formatted input and output functions. The format string determines the format of the input and output. The format string always starts with a '%' character.
The commonly used format specifiers in printf() function are:
%d or %iIt is used to print the signed integer value where signed integer means that the variable can hold both positive and negative values.
%uIt is used to print the unsigned integer value where the unsigned integer means that the variable can hold only positive value.
%oIt is used to print the octal unsigned integer where octal integer value always starts with a 0 value.
%xIt is used to print the hexadecimal unsigned integer where the hexadecimal integer value always starts with a 0x value. In this, alphabetical characters are printed in small letters such as a, b, c, etc.
%XIt is used to print the hexadecimal unsigned integer, but %X prints the alphabetical characters in uppercase such as A, B, C, etc.
%fIt is used for printing the decimal floating-point values. By default, it prints the 6 values after
Let's understand the format specifiers in detail through an example.
printf("Value of b is:%d", b);
printf("\nValue of c is:%d",c);