C New Lines

By default printf keeps everything on one line. To move down to a new line, C uses a small special code called a newline character.

When you want output to appear on separate lines, you add \n inside the text. This is called the newline character, and it tells the screen to move the cursor to the start of the next line.

Two lines of output

#include <stdio.h>

int main() {
    printf("First line\n");
    printf("Second line");
    return 0;
}

Many Line Breaks in One String

You do not need a separate printf for each line. You can place several \n codes inside a single string, and each one starts a new line.

Three lines at once

#include <stdio.h>

int main() {
    printf("One\nTwo\nThree");
    return 0;
}

Other Escape Sequences

The newline is one of several special codes that begin with a backslash. These are called escape sequences, and they let you include characters that would otherwise be hard to type.

Escape sequenceResult
\nStarts a new line
\tInserts a tab space
\\Prints a single backslash
\"Prints a double quote

Using a tab

#include <stdio.h>

int main() {
    printf("Name:\tAda\n");
    printf("Field:\tComputing");
    return 0;
}
Note: The \n is two characters when you type it, but the computer treats it as one single newline character.
Note: It is good practice to end your output with a \n. Many terminals look tidier when the final line finishes with a line break.