在C中,为什么这两段代码会给出相同的输出?
#include<stdio.h>
int main(void)
{
const char c='\?';
printf("%c",c);
}
和
#include<stdio.h>
int main(void)
{
const char c='?';
printf("%c",c);
}
据我所知,当我们使用printf()时,反斜杠用于生成引号("
或'
)和编译器的反斜杠,但为什么这对'?'有效?
答案 0 :(得分:86)
\?
是一个完全等同于?
的转义序列,用于转义trigraphs:
#include <stdio.h>
int main(void) {
printf("%s %s", "??=", "?\?="); // output is # ??=
}
答案 1 :(得分:28)
答案 2 :(得分:20)
因为'\?'
是有效的escape code,并且等于问号。
答案 3 :(得分:0)
当您定义conda install numpy
或char
时,编译器将string
或char
中的反斜杠解析为转义序列。
答案 4 :(得分:-1)
**
the simple answer of your question is
\? means ?. instead of using \? you can using ? .
\? is escape representation and ? is character representation means both are same.
我已将图片链接起来,以便您更轻松地理解它。
**
"click here to see the image " --> in this image you need to find \? in Escape character