Format specifiers


The format specifier is used during input and output. It is a way to tell the compiler what type of data is in a variable during taking input using scanf() or printing using printf().

format specifier for int

Format specifierDescription
%dData is display as decimal signed integer
%oDisplayed as octal integer
%xDisplayed as hexadecimal integer (Lower case hexadecimal digitis A to F and digits 0 to 9)
%XDisplayed as hexadecimal integer (Upper case hexadecimal digitis A to F and digits 0 to 9)
%iDecimal ,integer , hexadecimal
%uDisplayed as unsigned integer
%hdisplayed as short integer

format specifiers for float

Format specifierDescription
%fData is displayed as a floating point value without exponent.
%eDisplayed as floating point with exponent[Lower case ‘e’ while printing
%EDisplayed as floating point with exponent [Upper Case ‘E’ while printing.

format specifiers for Char

Format specifierDescription
%cData is displayed as a character.
%sDisplayed as a string

double :- %lf displayed as long float.
Long int:- %ld data is displayed as long integer

Output Format

ProgramOutput
printf(“\n””);symbol “ is displayed on the screen.
printf(“\n’”);symbol ‘ is displayed on the screen.
printf(“\?”);symbol ? is displayed on the screen.
printf(“\\”);symbol \ is displayed on the screen.
printf("t");tab
printf(“\r”);cursor move beginning of new line.
printf(“\a”);Beep sound (alarm).
printf(“\n”);New line
printf(“\b”);Cursor move towards left by position deleting the character which been displayed earlier.