C Format Specifier
C Format Specifier
The C format specifier is used for input and output and It is a method to tell the compiler what type of data is in a variable during taking input using scanf() or printing using printf() these are %c, %d, %f, etc and it pointed that the type of data to be printed on standard output.
Format specifier | Description |
---|---|
%d or %i | %d is pointed to print the signed integer value that the variable can hold both positive and negative values. |
%u | %u is used to print the unsigned integer value that the variable can hold only a positive value. |
%o | %o is used to print the octal unsigned integer and it is the value that always starts with a 0 value. |
%x | %x used to print the hexadecimal unsigned integer a value always starts with a 0x value. %x printed in small letters such as a, b, c, etc. |
%X | %X used to print the hexadecimal unsigned integer, prints the alphabetical characters in uppercase such as A, B, C, etc. |
%f | %f used for printing the decimal floating-point values. |
%e/%E | %e is used for scientific notation. |
%g | %g is used to print the decimal floating-point values i.e., the value after the decimal in the input will be the same as the value in the output. |
%p | %p used to print the address in a hexadecimal form. |
%c | %c used to print the unsigned character. |
%s | %s used to print the strings. |
%ld | %ld is used to print long-signed integer values. |
For Signed Integer format specifier: %d, %i
Program
#include <stdio.h> int main() { int x = 87, y = 66; printf("%d\n", x); printf("%i\n", x); return 0; }
Output
87 87
Character format specifier: %c
Program
#include <stdio.h> int main() { char ch = 'B'; printf("%c\n", ch); return 0; }
Output
B