Get the App
SLTechnology News&Howtos  ›  Development  › 

What are the escape characters in C language and how to use them?

Shulou Source: shulou.com Published: 2022-05-31 17:46:10 10月04日 Update

This article mainly introduces "what are C language escape characters and how to use them". In daily operation, I believe many people have doubts about what C language escape characters are and how to use them. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful for you to answer the doubts about what C language escape characters are and how to use them. Next, please follow the editor to study!

What is an escape character

Simple understanding: a character that can convert the meaning of a character.

Summary table of escape characters

Detailed explanation of common escape characters

1 escape character "\?"

Function: used when writing consecutive question marks to prevent them from being parsed into three-letter words

2 escape character "\"

Function: used to represent character constants

For example:

# includeint main () {printf ("\"); / / will print a'(single quotation mark) return 0;}

3 escape character "\"

Function: used to indicate double quotation marks inside a string

For example:

# includeint main () {printf ("\"); / / will print "(double quotation marks) return 0;}

4 escape character "\"

Function: used to represent a backslash to prevent it from being interpreted as an escape sequence.

For example:

# includeint main () {printf ("\"); / / will print out\ (backslash) return 0;}

5 escape character "\ a"

Function: warning character, buzzing.

6 escape character "\ n"

Function: line break

For example:

# includeint main () {printf ("abc\ ndef"); / / will print abc and def in two lines return 0;}

6 escape character "\ r"

Function: enter

7 escape character "\ t"

Function: horizontal tabs

Description: equivalent to pressing the tab key on the keyboard.

8 escape character "\ ddd"

What it does: ddd represents 1 to 3 octal numbers. Such as:\ 130

For example:

# includeint main () {printf ("% c\ n",'\ 130'); / / print X / / octal: 130 / / 10: 88 (SCII:X) return 0;}

9 escape character "\ xdd"

Purpose: dd represents 2 hexadecimal digits. Such as:\ x44

For example:

# includeint main () {printf ("% c\ n",'\ x44'); / / print D / / hexadecimal: x44 / / 10: 68 (SCII code: d) return 0;} Summary

After introducing the above, how on earth do you use escape characters? Let's explain it with a title.

Topic: print\ test\ 628\ test.c

For example:

# includeint main () {printf ("\\ test\\ 628\\ test.c\ n"); / / the\ t horizontal tab / /\ 62 octal / / to prevent them from being escaped, we need to add "\" return 0 At this point, the study of "what are the escape characters in C language and how to use them" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Tags: Characters escape function language binary learning quotation marks octal tabs numbers slashes more horizontal topic tabulation help practical and then together hexadecimal Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno macOS MariaDB Apple Redmi Linux