Format Specifiers and Escape Sequences in C Programming

Format Specifiers

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

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 SEQUENCESDESCRIPTION
\aalarm or beep or bell
\bbackspace
\fForm feed
\nNew Line
\rCarraige Return (reset the device’s position to the beginning of a line)
\tHorizontal Tab
\vVertical Tab
\\Backslash
\’Single Quote
\”Double Quote
\?Question Mark(used to avoid trigraphs)
\nnnInterpreted as an Octal Number
\xhhInterpreted as a Hexadecimal Number
\0Null
\eEscape character
\UhhhhhhhhUnicode code point. H is a hexadecimal digit
\uhhhhUnicode code point below 10000 hex.


Example: