Escape sequence in c programming; Through this tutorial, you will learn what is escape sequence and how to use it in c programming.
An escape sequence is a sequence of characters that does not represent itself when used inside a character or string literal, but is translated into another character or a sequence of characters that may be difficult or impossible to represent directly.
List of Escape Sequences in C
| Escape Sequence | Meaning |
|---|---|
| \a | Alarm or Beep |
| \b | Backspace |
| \f | Form Feed |
| \n | New Line |
| \r | Carriage Return |
| \t | Tab (Horizontal) |
| \v | Vertical Tab |
| \\ | Backslash |
| \’ | Single Quote |
| \” | Double Quote |
| \? | Question Mark |
| \nnn | octal number |
| \xhh | hexadecimal number |
| \0 | Null |
Here are some basic examples of escape sequence characters in c; as shown below:
- \n Escape Sequence
- \t Escape Sequence
- \b Escape Sequence
- \a Escape Sequence
\n Escape Sequence
#include <stdio.h>
int main()
{
printf("Hello \nProgrammer ");
return 0;
}
Output
Hello Programmer
\t Escape Sequence
#include <stdio.h>
int main()
{
printf("Hello\tProgrammer ");
return 0;
}
Output
Hello Programmer
\b Escape Sequence
#include <stdio.h>
int main()
{
printf("Hello\b Programmer ");
return 0;
}
Output
Hell Programmer
Note that :- \b will backspace a character.
\a Escape Sequence
#include <stdio.h>
int main()
{
printf("This will make a bell sound\a ");
return 0;
}
Output
This will make a bell sound
Note that :- \a will audio you a bell sound 🔔.
Conclusion
Thus, the article covered in detail about the various escape sequences available in c. Also, the article covered the various escape sequences by explaining some with appropriate examples.