Using format specifier the compiler can understand that what type of data a user wants to process as an input and output operation. It is mainly used for input and output purposes.
format specifiers tells that what type of data is storing in a variable using scanf() or printing using printf() decided by format specifiers?
When a value is stored in a particular variable, then you cannot print the value stored in the variable straightforwardly without using the format specifiers.
FORMAT SPECIFIER | TYPE |
---|---|
%c | Character |
%d | Signed integer |
%e or %E | Scientific notation of floats |
%f | Float values |
%g or %G | Similar as %e or %E |
%hi | Signed integer (short) |
%hu | Unsigned Integer (short) |
%i | integer |
%l or %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 |
Escape sequences are a sequence of characters that represent a different meaning when used in a string literal. Escape sequences are the same for many other programming languages like java, c++, c#, etc. They usually begin with the ‘\(backslash)’ symbol. Here is a list of escape sequences:
ESCAPE SEQUENCES | DESCRIPTION |
---|---|
\a | alarm or beep or bell |
\b | backspace |
\f | Form feed |
\n | New Line |
\r | Carraige Return (reset the device’s position to the beginning of a line) |
\t | Horizontal Tab |
\v | Vertical Tab |
\\ | Backslash |
\’ | Single Quote |
\” | Double Quote |
\? | Question Mark(used to avoid trigraphs) |
\nnn | Interpreted as an Octal Number |
\xhh | Interpreted as a Hexadecimal Number |
\0 | Null |
\e | Escape character |
\Uhhhhhhhh | Unicode code point. H is a hexadecimal digit |
\uhhhh | Unicode code point below 10000 hex. |