C Format Specifiers and Escape Sequences With Examples: C Tutorial In Hindi
Format specifier in C:-
The format specifier in C programming is used for input and output purposes. Through this, we tell the compiler what type of variable we are using for input using scanf() or printing using printf(). Some examples are %d, %c, %f, etc.
The %c and %d used in the printf( ) are called format specifiers. The format specifier tells printf( ) to print the value, for %c, a character will be printed, and for %d, a decimal will be printed. Here is a list of format specifiers.
Format Specifier | Type |
%c | Used to print the character |
%d | Used to print the signed integer |
%f | Used to print the float values |
%i | Used to print the unsigned integer |
%l | Used to a long integer |
%lf | Used to print the double integer |
%lu | Used to print the unsigned int or unsigned long integer |
%s | Used to print the String |
%u | Used to print the unsigned integer |
Following are the few examples of format specifier:
- To print the integer value:
- To print the float value:
- To print the character:
- To print the string:
What is Escape Sequence in C?
Many programming languages support the concept of Escape Sequence. An escape sequence is a sequence of characters that are used in formatting the output. They are not displayed on the screen while printing. Each character has its own specific function like \t is used to insert a tab and \n is used to add a newline.
Types of Escape Sequence in C
Escape Sequence | Description |
\t | Inserts a tab |
\b | Inserts a backspace |
\n | Inserts a newline. |
\r | Inserts a carriage return. |
\f | Inserts a form feed. |
\’ | Inserts a single quote character. |
\” | Inserts a double quote character. |
\\ | Inserts a backslash character. |
Following are some examples of escape sequence:
- Print character backslash(\) using printf function
- Prints a newline before and after the text
- Use \" to print double quote and \' for a single quote
- To provide tab space between two words
- To add a vertical tab character.
0 Comments