C - Use escape sequences

Introduction

To write characters that you cannot type into your source code, C uses escape sequences.

The escape sequence uses the backslash character followed by a second character or symbol:

\n 

That's the escape sequence for the newline character.

The following table lists the standard C language escape sequences.

Escape SequenceCharacter It Produces
\a Bell ("beep!")
\b Backspace, non-erasing
\f Form feed or clear the screen
\n Newline
\r Carriage return
\t Tab
\v Vertical tab
\\ Backslash character
\? Question mark
\' Single quote
\" Double quote
\xnn Hexadecimal character code nn
\onn Octal character code nn
\nnOctal character code nn

The following code adds the newline character at the end of every printf() text string.

Demo

#include <stdio.h>

int main()//w  w w  .  j  a v a  2 s .c  om
{
    printf("Hi\n");
    printf("C\n");
    printf("from\n");
    printf("www.\n");
    printf("book2s.com\n"); 
    return(0);
}

Result

Related Topic