'' /''
1. Escape character: change meaning
without adding "\"
int main()
{
printf("C: \test\32\test.c\n");
//\\用于表示一个反斜杠,防止它被解释转义为一个转义序列
return 0;
}
Run screenshots
plus "\"
int main()
{
//\是为了转义其他字符的
printf("%s\n", "\"");
printf("%s\n", "\"");
printf("%s\n", "abc");
printf("%c\n", '\'');
printf("C: \\test\\32\\test.c\n");
//\\用于表示一个反斜杠,防止它被解释转义为一个转义序列
printf("(Are you OK\?\?)\n");//??+)-->三字母词
return 0;
}
operation result
int main()
{
printf("%c\n", '\x61');
printf("%c\n", '\42');
//\ddd-->ddd表示1-3个八进制数字
//\xdd-->dd表示十六进制数字
//\42--42是2个八进制数字
//42作为八进制代表的那个十进制数字,作为ASCII码值,对应的字符
//42--->十进制 34,作为ASCII码值代表的字符
return 0;
}
The result of the operation is
2. Notes
- Some unnecessary codes in the code can be deleted directly or commented out
-
Some of the code is more difficult to understand, you can add a
comment. There are two styles of text comments.- C language comment style
/ xxxxxx /
disadvantage is that it cannot be nested
- C language comment style
- C++ language comment style
//xxxxxxx
can be nested
3. The end mark of the string is an escape character of "\0". When calculating the length of the string, \0 is the end sign, and the content of the string is not used.
For example,
before adding "\0"
// string type
int main()
{
char arr1[] = "abc";//数组
char arr2[]={ 'a','b','c'};
printf("%s\n", arr1);
printf("%s\n", arr2);
return 0;
}
The code after "\0" is added to the running result
#include<stdio.h>
//字符串类型
int main()
{
char arr1[] = "abc";//数组
char arr2[]={ 'a','b','c','\0'};
printf("%s\n", arr1);
printf("%s\n", arr2);;
return 0;
}
The results of the operation are now
back to normal