当前位置:网站首页>[C language] string, escape character and comment
[C language] string, escape character and comment
2022-07-19 09:56:00 【Lixinze__】
Catalog
character string
A string of characters enclosed in double quotes is a string literal , Abbreviated string .
char Is a character type , There is no string type .
But strings can be stored in character arrays :
char arr[10] = "abcdef";The above has opened up 7 Space of characters
[ ] You may not fill in , Automatically open up the corresponding space according to the following string content
The end of a string is a \0 Escape character , When calculating the length of a string \0 Only the end sign , No string content

arr2 Chinese characters only take up part of the space , Then there are many characters ,\0 Is the end of a string , So you should stay behind the space until you encounter \0 To terminate .
strlen Is a library function for finding the length of a string ,string length, The header file string.
strlen Is used to obtain the effective length of the string , The closing mark '\0' Not included .
strlen The rules obtained are very simple : From front to back , Until I met '\0' Yes, stop the detection .
Character array is not a valid string , Because there is no... In the back '\0', therefore strlen In solving the problem , After detecting valid characters , It will continue to detect backwards , Until I met '\0' Yes, it ends , So the first after uncertainty '\0' In what position .
Escape character
Escape character | paraphrase |
\? | Use... When writing multiple consecutive question marks , Prevent them from being parsed into three letter words |
\' | Used to represent character constants |
\“ | Double quotation marks used to represent the inside of a string |
\\ | Used to indicate a backslash , Prevent it from being interpreted as an escape sequence character . |
\a | Warning characters , Beep |
\b | Back space |
\f | Paper in |
\n | Line break |
\r | enter |
\t | Horizontal tabs |
\v | Vertical tabs |
\ddd | ddd Express 1~3 Eight octal numbers . Such as : \130 X |
\xdd | dd Express 2 Hexadecimal numbers . Such as : \x30 0 |
\n
int main()
{
printf("abcn");
printf("abc\n")// A newline
return 0;
}\0
int main()
{
printf("abc0def")// Print abcdef
printf("abc\0def")// Print abc
return 0;
}
\?
// Three letter words
//??) - ]
//??( - [
int main()
{
printf("%s\n","(are you ok??)")
// Print the results (are you ok]
printf("%s\n","(are you ok\?\?)")
// Print the results (are you ok??)
// The current compiler does not support three letter words
return 0;
}\'
int main()
{
printf("%c\n",''');// Report errors
printf("%c\n",'\'');// Represents a character constant '
return 0;
}
\"\"
int main()
{
printf("abcdef");// Only strings can simplify printing directly
printf("a");// There can be only one character in the string
printf(""");// Report errors
printf("\""); Double quotation marks inside a string
return 0;
}\\
int main()
{
printf("abcd\0ef");// Print the results abcd
printf("abcd\\0ef");// Print the results abcd\0ef
// Represents a backslash , Prevent it from being interpreted as an escape sequence character .
printf("c:\test\test.c");// Print the results c: est est.c
printf("c:\\test\\test.c");// Print the results c:\test\test.c
// For path printing \\
return 0;
}\a
int main()
{
printf("\a\a\a\a\a\a\a");
// Warning characters , Beep
return 0;
}\t
int main()
{
printf("abcd\tef");
//Tab = \t
return 0;
}\ddd
int main()
{
printf("%c\n",'\130');//ddd Express 1~3 Eight octal numbers
// Print the results X, by 130 This octal is converted to a decimal number as ASCII The character represented by the code value
return 0;
}character \0 Of ASCII The code value is 0
Letters are case ASCII Code value difference 32

\xdd
int main()
{
printf("%c\n",'\x60');
return 0;
}The following is the format of the print data
//%d - Print shaping
//%c - Print character
//%s - Print string
//%f - Print float Data of type
//%lf - Print double Data of type
//%zu - Print sizeof The return value of notes
- Notes can sort out ideas
- Comments can explain complex code
边栏推荐
- ES Restful操作
- [C language] summary of function knowledge points
- [C language] storage of floating-point type in memory
- Brilliant use output
- 18、shell脚本编程(1)
- C language force buckle question 25 of K a group of inverted linked list. Multi pointer traversal
- Chapter 10 stack of STL
- 华为无线设备配置静态负载均衡
- D. Mark and Lightbulbs
- 金属有机骨架材料/聚合物复合材料ZIF-8/P(TDA-co-HDA)|氧化锌[email protected](Fe)复合纳米材料
猜你喜欢

Componentized advanced -- slot

Add - before the command in makefile to ignore the error caused by the command and continue to execute the next command

Chapter 10 stack of STL

标准化、归一化和正则化的关系

闲谈工业企业全厂信息化规划

565. Array nesting / Sword finger offer II 001 Integer division

【摸鱼神器】UI库秒变低代码工具——表单篇(二)子控件

Questions d'entrevue - concevoir des cas d'essai pour:: memcpy

Talking about the informatization planning of industrial enterprises

第一部分—C语言基础篇_6. 函数
随机推荐
第十一章 STL 之 queue
how to use culasLt
pip和pip3的区别用法详解
纳米银颗粒负载UiO-66|Fe3O4/Cu3(BTC)2金属有机骨架(MOF)纳米复合材料|NaGdF4:Yb,Er上转换纳米粒子@ZIF-8
【ACWing】947. text editor
氟改性UiO-66|3,4-二羟基苯甲醛改性UiO-66-NH2|喜树碱衍生物/寡肽@ZIF-8纳米载药体系
第一部分—C语言基础篇_3. 运算符与表达式
[fishing artifact] UI library second low code tool - form part (II) sub control
状态码的故事
Develop the first Flink app
Go exceed API source code reading (II) -- openFile ()
浏览器的故事
Chapter IX deque of STL
齐岳供应负载亚甲基蓝的CuMOF纳米晶|原位生长在泡沫镍上FeMOF纳米片|氧化物纳米线/ZIF系MOFs糖葫芦状复合材料
How to correctly execute jedis unit test
D. Mark and Lightbulbs
rhcsa 第一天 7.11
Relationship between standardization, normalization and regularization
【摸鱼神器】UI库秒变低代码工具——表单篇(二)子控件
2022.7.16-----leetcode. Sword finger offer 041