C Special Characters

C Tutorial

 C Special Characters (Escape Sequences) – Complete Guide

In C language, special characters (also called escape sequences) are used to represent non-printable characters or to give special meaning inside strings and character literals.

They always start with a backslash (\).


 What Are Special Characters in C?

Special characters are escape sequences that tell the compiler to perform a special action, such as a new line, tab, beep sound, etc.

Example:

Output:

Hello
World

 Most Common Special Characters

EscapeMeaning
\nNew line
\tHorizontal tab
\rCarriage return
\bBackspace
\fForm feed
\vVertical tab
\\Backslash
\'Single quote
\"Double quote
\?Question mark
\0Null character

\n – New Line (Most Used)

Output:

C
Programming
  •  Moves cursor to next line

\t – Tab Space

Output:

Name Age
  •  Adds horizontal spacing

\\ – Backslash

Output:

C:\Program Files\
  •  Required because \ is escape starter

\" and \' – Quotes Inside String


\b – Backspace

Output:

AC
  •  Removes previous character

\r – Carriage Return

Output (system dependent):

World
  • Cursor returns to beginning of line

\0 – Null Character (Very Important)

  •  Marks end of string
  •  Used internally by all C strings

 Octal Escape Sequences

Output: A
(101 is octal for ASCII 65)


 Hexadecimal Escape Sequences

 Output: A
(41 is hex for ASCII 65)


 Special Characters vs Normal Characters

  •  Different meanings

 Common Mistakes

  •  Forgetting \
  •  Using \n outside string or char
  •  Confusing \0 with '0'
  •  Expecting \b to work in all terminals

 Interview Questions (Very Important)

  1. What is \n in C?

  2. Difference between \0 and '0'

  3. Why \\ is used?

  4. What is escape sequence?

  5. What happens if \0 is missing in string?


 Real-Life Use Cases

  • Formatting output

  • String handling

  • File writing

  • Console UI alignment

  • Embedded & system programming


 Summary

  • Special characters start with
  •  Used for formatting & control
  • \n and \t are most common
  • \0 terminates strings
  •  Must-know for interviews & real coding

You may also like...