Escape Sequence in C

An escape sequence is a sequence of characters that does not represent itself when used inside a character or string literal.

In C, all sequences consist of two characters, the first of which is the backslash, \ (called the "Escape character"); the remaining characters determine the interpretation of the escape sequence.


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


Example programs of some of the commonly used escape sequences:-

1. '\n'

#include <stdio.h>
int main() {
    printf("Hello,\n");
    printf("How are you?");
    return 0;
}

2. '\t'

#include <stdio.h>
int main() {
    printf("Hello,\t How are you?");
    return 0;
}

3.  ' \b '

#include <stdio.h>
int main() {
    printf("Hello,,\b How are you?");
    return 0;
}

4. ' \v '


#include <stdio.h>
int main() {
    printf("Hello,");
    printf("\v How are you?");
    return 0;
}

5. ' \\ '  ,  ' \' '  ,  ' \" '  &  ' \? '


#include <stdio.h>
int main() {
    printf("Slash :- \\");
    printf("Single Quote :- \' ");
    printf("Double Quote :- \" ");
    printf("Question Mark:- \? ");
    return 0;
}

Click on the title of above examples to run those codes on the c playground.


See my more posts about C programming here 
👇



Comments

Popular posts from this blog

ATM solution in C language.- Codechef

MOTIVATION SOLUTION IN C LANGUAGE | CODECHEF | IMDB

APPLE AND ORANGE | HACKERRANK | PROBLEM SOLVING | SOLUTION IN C