Escape Sequences in C Language | Escape Characters in C

Escape-Sequences-in-c-programming-language

Introduction:

In our previous article, We looked at the Variables in C-Language. In this article We are going to discuss Escape Sequences in C programming language. We will learn what is mean by Escape sequences in C and how to use escape characters.

Escape Sequences in C:

Most of the characters C-Language are printable characters. But there are few characters which can’t be printed on to console.

The characters like New line, Tab, Backslash, etc can’t be printed directly. So to print these kind of non-printable characters we use the Escape sequences.

Escape sequences in programming is a special sequence of characters, which is used to escape the meaning of the sequence to give it a different meaning.

An Escape sequences in C Language always start with the backslash ( \ ) character and followed by one or more characters.

For Example the new line character in C printed by using  '\n' Escape Character. This type characters refers to single sequence even though they are written in two characters.

Similarly, We use to print the tab, We will use the backslash '\' and character 't' together to form the escape sequence '\t' which will be used to represent the Tab.

List of Escape Sequences in C Language:

The Complete list of Escape Characters are Listed Below along with their ASCII value.

CharacterEscape SequenceASCII Value
Back Space \b08
Bell (Alert) \a07
Horizontal Tab \t09
New Line \n10
Vertical Tab \v11
Form Feed \f12
Carriage Return \r13
Quotation Mark \"34
Apostrophe \039
Backslash \\092

Now we have seen the list of escape characters, Let’s see how we can use them in program to get the desired output.

Examples to understand the Escape Sequences in C Programming:

New line ( “\n” ) Escape Character usage:

We use "\n" for new line character.

Program:

Output:

As you can see the "\n" character bring the printing to new line.

Let’s see same example without "\n" escape sequence.

Program:

Output:

Example 2: Printing Quotes and Backslash in C Language:

As we discussed earlier we can’t directly print the quotes (") and backslash ("\") characters. So we need to use the backslash character to escape these letters.

Program:

Output:

As you can see the backslash infront of the Quote and backSlash.

📢 To print the black-slash character on console, We need to use another back-slash character as escape character.

Related Articles:

Venkatesh

Hi Guys, I am Venkatesh. I am a programmer and an Open Source enthusiast. I write about programming and technology on this blog.

You may also like...

1 Response

  1. […] the previous article, We discussed about the Escape Sequences in C programming Language. In today’s article, We will learn about the different Datatypes in C […]

Leave a Reply