当前位置:网站首页>[C language series] - string + partial escape character explanation + annotation tips
[C language series] - string + partial escape character explanation + annotation tips
2022-07-29 05:35:00 【Gancheng なつき】
꧁ Hello, everybody ! It is a great honor to have your visit , Let's have a long way to go in programming !꧂
* Blog column :【C All living things 】*
Introduction to this article : character string + Partial escape character + Notes tips detailed introduction !
Get to know the author : Aspire to be a great programmer , Xiaobai, who is currently a sophomore in College .
Inspirational terms : The tediousness of programming , Let's study together and become interesting !
Text begins
List of articles
Summary of common escape characters
Explanation of several common escape characters
character string
Let's first look at a small piece of code :
”hello world.\n"
Last time we mentioned characters ( Like this, ‘w’ ), It's just a character , Such a string composed of multiple characters with double quotation marks is called the literal value of the string (String Literal), Abbreviated string .
Here I want to give you a small note , Also very important is :
The end of a string is a ‘\0’ The escape character of , When calculating the length of a string ‘\0’ It's the end sign , But it doesn't count the contents of the string .
Learned knowledge , Let's do a code topic ——————>>>
#include<stdio.h>
int main()
{
char arr1[] = "abc";
char arr2[] = { 'a','b','c' };
char arr3[] = { 'a','b','c','\0' };
printf("%s\n", arr1);
printf("%s\n", arr2);
printf("%s\n", arr3);
return 0;
}
Let's try , Ask what these three print respectively ?
Ha ha ha , Here we should highlight '\0' The importance of , Let's analyze this code ,
After the analysis , Let's take a look , Print the results ,
The result print of code 2 appears ,( To scald ) Such random values
Escape character
Before talking about escape characters , Let's first look at a written test question about escape characters
#include<stdio.h>
int main()
{
printf("c:\code\test.c\n");
return 0;
}
As you can see, there are many in this code With '\' start , Form followed by a letter , Some of these are escape characters ,
Let's analyze this code .
Look at the print results after analysis , Is it the same as a feather ------------->>>
Next, let's learn more about escape characters , First, let's look at a summary of strings !
Summary of common escape characters
Explanation of several common escape characters
\?
Speaking of \? This escape character , It should be supported by compilers a long time ago ( such as :VC 6.0), This compiler
Add a \ Then it will not be parsed into three letter words , Of course, this is now vs2013 The above version cannot be demonstrated , So there's no demonstration !
\'(\")
When you just want to print on the screen \' What to do when , Look at this little code
#include<stdio.h>
int main()
{
printf("%c\n", '\'');
return 0;
}
The result of this printing is a single ‘ Character
\ddd
The demonstration of escape characters also depends on a piece of code and analysis !
#include<stdio.h>
int main()
{
printf("%c\n", '\130');
return 0;
}
Look at the results
Why do you print uppercase characters X Well ? This is just like ASCII The code table is related to , interested , You can search the Internet ASCII Look at the code table , I won't explain it in detail here !
\xdd
#include<stdio.h>
int main()
{
printf("%c\n", '\x30');
return 0;
}
Here corresponds to hexadecimal conversion
Let's see the result
summary : Escape characters are so simple , I've learned , Iron !!!
Notes tips
When we write code in the source file, we usually need to write some comments , When writing wrong code , But I don't want to delete , At this time, you need the annotation function of the compiler , Introduce two annotation methods
There are two styles of annotation :
C Notes on language style /*xxxxxx*/
defects : You can't nest comments
C++ Style notes //xxxxxxxx
You can comment on one line or multiple lines
Conclusion
Okay , Today's blog sharing is over , Thank you bloggers for watching !!!
边栏推荐
- Li Kou 994: rotten orange (BFS)
- 【C语言系列】— 字符串+部分转义字符详解+注释小技巧
- Clickhouse learning (x) monitoring operation indicators
- 微信小程序-组件传参,状态管理
- Day 3
- 时间复杂度和空间复杂度
- 【C语言系列】—三种方法模拟实现strlen库函数的方法
- Alibaba cloud and Dingjie software released the cloud digital factory solution to realize the localized deployment of cloud MES system
- Detailed explanation of exit interrupt
- ClickHouse学习(四)SQL操作
猜你喜欢
随机推荐
C language first level pointer
【C语言系列】— 把同学弄糊涂的 “常量” 与 “变量”
Do students in the science class really understand the future career planning?
Alibaba cloud architect details nine trends in the game industry
浅谈范式
JS deep copy - Notes
冒泡排序 C语言
167. Sum of two numbers II - enter an ordered array
href与src的区别
【C语言系列】—三种方法模拟实现strlen库函数的方法
ClickHouse学习(六)语法优化
基础爬虫实战案例之获取游戏商品数据
Realize simple database query (incomplete)
ClickHouse学习(十)监控运行指标
微信小程序-组件传参,状态管理
[C language series] - storage of deep anatomical data in memory (I) opening of summer vacation
Bubble sort c language
个人学习笔记
redis的基本使用
阿里云架构师细说游戏行业九大趋势