C Language Escape Sequence
×


C Language Escape Sequence

173

 In the C language, escape sequences serve as special codes used to instruct the computer to perform specific actions or represent certain characters within a string.

 Escape Sequences are special character combinations that represent characters that are difficult to type directly in string.

 These Sequences always start with a Backslash() and use characters such as Newline(/n),Tab(/t), Backspace(/b), Carriage Return(/r), and many more.

 Escape Sequences are commonly used in strings to handle Formatting and Special Characters.

Common Escape Sequences 

1'\n' starts newline.

2' \t'Insert new tab.

3'\r' It moves the cursor to the beginning.

4'\b' It moves the cursor one space back.

5'\\' Insert backslash itself. since '\' is used to start the escape sequence.

6'\'Insert a single quote character.

7'/b' Insert double quote character.

8'\0'Represents a null character.

9'\a' Produces audible or visible alert.

10'\f'Advances the cursor to the next page.

11'\v'Insert vertical tab.

12'\?' Represent question mark character.

13'\0oo'Represents a character in octal notation.

14'\xhh' Represents a character in hexadecimal notation.

15'\unnnn' Represents a Unicode character.

These escape sequences are used to represent a special character within a string in C Programming.

Example:

#include<stdio.h>
int main()
{
printf("C\t Programming\n");
printf("backlash: \\ \n");
printf("single quote: \' \n");
printf("double quote: \" \n");
printf("alert sound: \a \n");
printf("carriage return: C\rProgramming \n");
return 0;

}

Output:

C Programming 
backlash: \
single quote: '
double quote: "
alert sound:
carriage return: Programming
In this example, various escape sequences are used within the printf.

The Output shows how this escape sequence affects the formatting and content of the displayed string.



Best WordPress Hosting


Share:


Discount Coupons

Get a .COM for just $6.98

Secure Domain for a Mini Price



Leave a Reply


Comments
    Waiting for your comments