Escape sequences in C are particular character combinations used to represent specific characters or control characters within a string or character constant. They are denoted by a backslash () followed by a specific character or sequence.
Some commonly used escape sequences in C:
Additionally, there are a few numeric escape sequences that represent characters using their ASCII or Unicode values:
It’s important to note that the behavior of escape sequences may vary depending on the context in which they are used, such as in strings, character constants, or output functions like printf().
Escape sequences are useful for representing special characters, controlling formatting, and inserting non-printable characters within C strings or character constants.
#include <stdio.h>
int main() {
// Using \x (Hexa) and \"
char ch = '\x41'; // ASCII value for 'A'
printf("English Alphabet starts at: \"%c\"\n", ch);
// Using \t and \n
printf("\nName \tAge \nRama \t33 \nAmmu \t29 \n");
// Using \0
printf("\nWhen I am visible \0, he wont be visble \n");
// Using \yyy (Octal)
printf("\nOur Class Strength in Octal is: \110\n");
//Using \b
printf("\nRama\b");
return 0;
}
Posted on: 15th June, 2023 in HPOJ.