简体   繁体   English

c语言中的字符初始化

[英]Character initialization in c language

I want to assign ' to a character but it keeps giving me error any help? 我想将'分配给一个角色,但它一直给我错误任何帮助?

    void main()
    {
        char c  = ''';
    }

Special characters like ' or \\ must be escaped with a backslash in these situations. 在这些情况下,必须使用反斜杠转义像'或\\这样的特殊字符。 In this particular case you got an error because the compiler thinks you opened and closed a null character with the first two '' and then opened another character without closing it with the third one. 在这种特殊情况下,您遇到错误,因为编译器认为您打开并关闭前两个''的空字符,然后打开另一个字符而不用第三个字符关闭它。

\\' represents Single quotation mark in C \\'表示C中的单引号

It is a standard escape sequence 这是一个标准的转义序列

Every time you want to assign ' , just need to assign \\' 每次你想要分配' ,只需要分配\\'

Use escape sequence: 使用转义序列:

char c  = '\'';

Also, a double quotation mark is written as '\\"' in C. 另外,双引号在C中写为'\\“'。

PS: No void main() , it should be int main(void) . PS:没有void main() ,它应该是int main(void)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM