[C] Introduction to escape characters and comments

escape character

The escape character, as the name suggests, is to change the meaning. It is to change the meaning of the original character and make it have another meaning. If we want to print a string of text
on the screen: c:\code:\test.c , our code will definitely be written like this:

#include<stdio.h>
int main()
{
    
    
	printf("c:\code:\test.c");
	return 0;
}

But the result of running this way is:
insert image description here
here is because of the shifting character, we failed to get the desired result. In C language, the compiler sees \ plus a letter after it, and the compiler thinks it needs to be escaped, so We can't print the result we want in this way. To print the correct result, we can use \ to escape twice. The reason can be understood as negative and negative. code show as below:

#include<stdio.h>
int main()
{
    
    
	printf("c:\\code:\\test.c");
	return 0;
}

In this way we can get the correct result.
Here I will show you the escape characters in C language:
insert image description here
\t here is equivalent to a Table with a length of 4. \ddd can be understood as the character corresponding to the octal number ddd (for example: \130 corresponds to 'X'), and \xdd can be understood as the character corresponding to the hexadecimal number dd (for example: \x30 is used for is '0').
Here is the ASCII code table for everyone, and you can correspond to it:
insert image description here
the first 32 characters that need to be noted here are non-printable characters, and when printing in octal or hexadecimal, do not exceed the range of ASCII, otherwise the consequences will be unimaginable.

note

Code that we don't use when writing code can be deleted or commented out.
When some code is more difficult, you can also add some comments to explain it.
The comment style of C++ //xxxxxxxxxx
can comment one line or multiple lines.
The comment style of C language /*xxxxxxxx*/
Its defect is that it cannot be nested.
You can see the code:

#include<stdio.h>
int Add(int x, int y)
{
    
    
	return x + y;
}

/*
C语言注释风格
int Sub(int x, int y)
{
	return x - y;
}*/

int main()
{
    
    
	//C++ 注释风格
	//int a = 10;
	//调用Add函数,完成加法运算
	printf("%d", Add(1, 3));
	return 0;
}

At this point, I believe that I already know what escape characters and comments are. That’s all for our sharing today. Thank you for your attention and support.

Guess you like

Origin blog.csdn.net/bushibrnxiaohaij/article/details/131209046