First acquainted with C language; escape characters; comments;

'' /''
1. Escape character: change meaning
First acquainted with C language; escape characters; comments;
without adding "\"

int main()
{   
    printf("C: \test\32\test.c\n");
    //\\用于表示一个反斜杠,防止它被解释转义为一个转义序列
    return 0;
}

Run screenshots
First acquainted with C language; escape characters; comments;
plus "\"
First acquainted with C language; escape characters; comments;

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
First acquainted with C language; escape characters; comments;

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
First acquainted with C language; escape characters; comments;

2. Notes

  1. Some unnecessary codes in the code can be deleted directly or commented out
  2. Some of the code is more difficult to understand, you can add a
    comment. There are two styles of text comments.

    1. C language comment style
      / xxxxxx /
      disadvantage is that it cannot be nested
  3. 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;
}


First acquainted with C language; escape characters; comments;
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
First acquainted with C language; escape characters; comments;
back to normal

Guess you like

Origin blog.51cto.com/14950896/2540529