谁能解释一下为什么这段代码在编译时不会出错?
int main()
{
// why doesn't the following line give a type mismatch error??/
return "success!";
}
最佳答案
因为三字母 ??/
被替换为 \
,这意味着返回被注释掉了。你的代码等同于
int main()
{
// why doesn't the following line give a type mismatch error\
return "success!";
}
与
相同int main()
{
// why doesn't the following line give a type mismatch error return "success!";
}
还要注意,在 main
中没有 return
语句的情况下,有一个隐式的 return 0;
,所以代码是定义明确。
关于c++ - 为什么在main中可以返回一个const char*?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22282777/