当前位置:网站首页>[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
边栏推荐
- Chapter 4 - first order multi-agent system consistency - > pilot follow system consistency [program code]
- Chapter 4 - first order multi-agent system consistency - > continuous time system consistency with time delay [program code]
- 5分钟就能轻松入门的机器学习基础知识
- CLWY权限管理(二)--- 用户模块
- Rhcsa day 1 7.11
- es索引、类型(mapping)、文档、ik分词器
- [C language] void type and void* pointer type
- 工程效能CI/CD之流水线引擎的建设实践
- 齐岳供应负载亚甲基蓝的CuMOF纳米晶|原位生长在泡沫镍上FeMOF纳米片|氧化物纳米线/ZIF系MOFs糖葫芦状复合材料
- [C language] storage of shaping data
猜你喜欢

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

The study found that DNA nano device injection can be safely used for medical purposes

The inflection point of eth may be just around the corner, which is how to

Build a server environment with node+express

Anaconda and jupyter notebook entry level detailed tutorial

CLWY权限管理(三)--- 用户组模块

Relationship between standardization, normalization and regularization

MySQL -- SQL optimization case -- implicit character encoding conversion

fiddler 重放攻击,简单的模拟重放攻击

Es index, type (mapping), document, IK word breaker
随机推荐
[动态规划]DP27 跳跃游戏(二)-中等
Clwy permission management (I) -- project construction
[C language] summary of array knowledge points
Brilliant use output
mof定制材料|双金属CuNi-MOF纳米材料|核—壳结构[email protected]纳米复合材料|ZIF-8/聚偏氟乙烯复合纳米纤维膜PVDF
npm使用
第十一章 STL 之 queue
Rhcsa day 1 7.11
Chapter 4 - first order multi-agent system consistency - > switching topology system consistency
Go exceed API source code reading (II) -- openFile ()
Chapter VIII vector of STL
Chapter 4 - first order multi-agent system consistency - > pilot follow system consistency [program code]
Part I - Fundamentals of C language_ 6. Function
二维数组与稀疏数组之间的转换
【摸鱼神器】UI库秒变低代码工具——表单篇(二)子控件
Mux256to1v,Hadd,Fadd
【565. 数组嵌套】
18、shell脚本编程(1)
Mutual access between components
Questions d'entrevue - concevoir des cas d'essai pour:: memcpy