Escape Characters in C Programming Language

C Escape Characters

Escape Characters in C Programming Language is a sequence of characters that doesn’t represent itself when used inside a character or a string literal but has its specific function.

Escape SequenceMeaning
\aAlarm or Beep
\bBackspace
\fForm Feed
\nFor New line
\rCarriage Return
\tTab (Horizontal)
\vVertical Tab
\oNull
\’Single quote
\”Double quote
\?Question Mark
\nnnOctal Number
\xhhHexa Decimal Number
\\We use it to display backslash character

Some Important Escape Examples:

  • \n New Line Character
  • \t Horizontal Space
  • // Hide unused data or comments
  • /* */ Used for many lines hide at same time.

1. \n – New Line Character

To use New Line character, it means if a name or paragraph is written in a sequence but we want to break out it and drop it in the second line then \n character can be used.
For Example:

#include <stdio.h>
#include <stdlib.h>
int main()
{
 printf("Hii!\nHow are you?\nWhat are you doing?");
    return 0;
}
 

Output:

Hii!
How are you?
What are you doing?

2. \t – Horizontal Space:

To use Horizontal Space, it means if a name or paragraph is written in a sequence but we want some space in it then \t character can be used.
For Example:

#include <stdio.h>
#include <stdlib.h>
int main()
{
 printf("Hii!\tHow are you?\tWhat are you doing?");
    return 0;
}
 
Hii!    How are you?    What are you doing?

3.// – Hide unused data or comments:

If you hiding data or comments one or more lines and show only used data then it was used.
For Example:

#include <stdio.h>
#include <stdlib.h>
int main()
{
 //printf("Hii!\n");
   printf("Hello\n");
   printf("How are you?\n");
   printf("I am fine\n");
 //printf("Ok.\n");
   printf("What are you doing?\n");
   printf("Learning C");
 
    return 0;
}
 
Hello
How are you?
I am fine
What are you doing?
Learning C

/* */ – Used for many lines hide at same time

Hiding many lines at the same time.
For Example:

#include <stdio.h>
#include <stdlib.h>
int main()
{
 //printf("Hii!\n");
   printf("Hello\n");
   printf("How are you?\n");
  /*printf("I am fine\n");
   printf("What are you doing?\n");
   printf("Learning C");*/
 
    return 0;
}
 
Hello
How are you?

If you have any problem in solving your questions, then join our Telegram group or search @Learnsimply, we will help you.

Please write comments if you find anything incorrect in the Escape Character lecture.

Leave a Comment

en English
X