Escape sequences in c

Escape sequences in c language

Welcome to this article, here we will discuss the various escape sequences in the c language.

Escape sequences are the special characters that we used inside our programming.

The backslash is considered an escape sequence because it causes an escape from the normal interpretation of a string so that the next characters have special meaning.

In c language there are many types of escape sequences are available such as-

\n, \b,\t,\r,\’,\” etc and these escape sequences have separate meanings and separate work also.

Various types of escape sequences in c language :

\n:

This is the most popular escape sequence used to move our cursor into the next lines.

Suppose if you want to print the hello programmers in separate lines then how you should do that, well most of the programmers will do wrong things by writing the text into separate lines, but that is not the correct method at all, and the program will appear in the same line.

So in this case we can use the \n escape sequence.

Example:

Printf(“hello\n”);

printf(“programmers”);

This is the correct method, here we mention the escape sequence in the same line, we can also write the text programmer in the same line also.

\t:

This is another escape sequence which we use for tab space.

Suppose you want spaces into your hello programmer text, so what the beginners do, they create spaces inside their program but that is not correct.

So to overcome this situation we can use the \t, which creates an 8 bits space in between two words.

Example:

#include<stdio.h>

int main()

{

Printf(“hello\tprogrammers”);

return 0;

}

This is a correct example of \t and it creates spaces in between two words.

\b:

Another kind of escape sequence is \b. Suppose if you want to go 1 step behind in this case we can use the \b escape sequence. It is used to give backspace.

Example:

printf(“surya\b”);

This will move our cursor in the character a and blink on that.

Printf(“surya\bdev”);

This will display the name surydev because of \b a erase and that surydev displayed.

printf(“surya\\bdev”)

this will display the name surdev , because of \b another character is erased, so in this method, we can use the \b characters inside the c program.

escape sequences in c language
escape sequences in c language

\r:

This is our next escape sequence which means carriage return. And with the help of this feature, our cursor will be removed into the first position.

Example:

printf(“surya\r”);

this will show the result surya and because of the \r s will blinked.

Printf(“surya\rdiv”);

This will displayed the result Divya instead of Surya because with the help of \r we already move our cursor in the first position and write Divya instead of Surya.

\a:

This is another escape sequence that introduces a beep alert sound into our computer.

Syatax:

int main()

{

printf (“surya\a”);

return 0;

}

\\:

This is another escape sequence which indicates a back slash.

Suppose if you want to print this \surya\dev then the program should like this.

printf(“\\surya \\dev”);

\”:

This is another type of escape sequence which is used to print a double quotation inside our programming.

Suppose if you want to print the “Surya dev ” then you have to program like this.

Printf(“\”surya dev\””);\

Conclusion:

In this article, we discussed the various types of escape sequences in the c language.

To read this kind of informational article please follow our websites.

Also read

Keywords in c programming
Variables in c language
Operators in c programming
Unary operators in c programming
Best youtube channel to learn c programming