C Escape Sequences

Beginner
6 min read
Updated: Nov 2026
1 example

What Is Escape Sequences?

An escape sequence is a backslash followed by a character that represents something hard to type directly, such as a newline (\n), a tab (\t), or a quote inside a string (\").

Remember
\n  newline        \t  tab          \\  backslash
\"  double quote   \'  single quote \0  null char
\r  carriage ret   \a  alert        \x41 hex 'A'

Cheat Sheet

Keep these facts handy while you work with Escape Sequences in C.

TopicDetail
Newline\n ends the current line
Tab\t jumps to the next tab stop
Quote in string\" prints a double quote
String end\0 marks the end of a C string

C Examples

Compile each example with gcc file.c -std=c11 -Wall -o out. Next: Operators.

Example 1 — Tabs, quotes, and backslashes

Escape sequences inside a string literal.

C
#include <stdio.h>

int main(void) {
    printf("Name\tScore\n");
    printf("Ann\t95\n");
    printf("She said \"hi\"\n");
    printf("Path: C:\\temp\\data\n");
    return 0;
}

How It Works

  1. \t inserts a tab between columns.
  2. \" lets a double quote appear inside the string.
  3. \\ prints one backslash.

Edge Cases & Pitfalls

Check these before relying on Escape Sequences in real programs.

path

Backslashes in Windows paths

"C:\new" contains \n, a newline. Write "C:\\new" or use forward slashes.

\0

Embedded \0

A \0 inside a string ends it early for functions like printf("%s") and strlen.

Key Takeaways

  • Backslash: starts every escape.
  • Quotes: escape the matching quote type.
  • NUL: \0 terminates strings.

One line: An escape sequence is a backslash followed by a character that represents something hard to type directly, such as a newline (\n), a tab (\t), or a quote inside a string (\").

Frequently Asked Questions

\n moves to a new line; \r returns the cursor to the start of the current line. Windows text files use \r\n, but C translates it for you in text mode.
Escape it as \\ inside a string or character literal.
Continue with "C Operators" next. Learn arithmetic, relational, logical, assignment, bitwise, conditional, and sizeof operators, plus precedence. The C Fundamentals hub lists every topic in order.

Next: Operators

Learn arithmetic, relational, logical, assignment, bitwise, conditional, and sizeof operators, plus precedence.

Continue →

CODETOFUN NEWS

Stay Ahead in Tech

Get the latest IT news, programming updates, and technology trends directly on your phone.

Your daily dose of tech, straight to your feed.

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

8 people found this page helpful