当前位置:网站首页>[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 !!!
边栏推荐
猜你喜欢
![[event preview] cloud digital factory and digital transformation and innovation forum for small and medium-sized enterprises](/img/6f/f7c5d605ea9b7b9e7c49ac716492ef.jpg)
[event preview] cloud digital factory and digital transformation and innovation forum for small and medium-sized enterprises

MySQL解压版windows安装

无重复字符的最长字串

Application of Huffman tree and Huffman coding in file compression

Alibaba cloud Zhang Xintao: heterogeneous computing provides surging power for the digital economy

【C语言系列】— 一道递归小题目

Day 3

数据库操作 Day 6

Selenium实战案例之爬取js加密数据

About local variables
随机推荐
【JS题解】牛客网JS篇1-10题
redis的基本使用
实现简单的数据库查询(不完整)
[C language series] - realize the exchange of two numbers without creating the third variable
时间复杂度和空间复杂度
阿里云架构师细说游戏行业九大趋势
适创科技以云仿真平台,支持“中国智造”升级
Detailed explanation of serial port communication
Selenium实战案例之爬取js加密数据
【TypeScript】深入学习TypeScript函数
科班同学真的了解未来的职业规划吗?
Clickhouse learning (IV) SQL operation
Occt learning 003 - MFC single document project
Topological ordering of a graph of water
Preemptive appointment | Alibaba cloud shadowless cloud application online conference appointment opens
Basic use of redis
浅谈Servlet
Day 3
虚拟增强与现实第二篇 (我是一只火鸟)
组件传参与生命周期