问题描述
Hello Grp,
我想知道为什么这是C中的错误
a> 3?返回1:返回2;
如果不是这样的话。
if(a> 3)
返回1;
其他
返回2;
是否会使函数处于未定义状态?
提前致谢,
问候,
Naren。
Hello Grp,
I want to know why this is an error in C
a > 3 ? return 1:return 2;
when this is not.
if(a > 3)
return 1;
else
return 2;
Is it going to leave the function in an undefined state?
Thanks in advance,
regards,
Naren.
推荐答案
否 - 这只是不正确的语法。查看C语法。
No - it simply is incorrect syntax. Check out the C grammer.
Naren,
返回< whatever> ;;
是一个语句,而不是表达式。您不能将它用作条件运算符的任何
操作数。您/可以/做什么,
当然是这样的:
返回> 3? 1:2;
HTH
问候
-
Irrwahn Grausewitz(ir ** *****@freenet.de)
欢迎来到clc:
clc faq-list:
acllc-c ++ faq:
Naren,
return <whatever>;
is a statement, not an expression. You cannot use it as any
operand of the conditional operator. What you /can/ do, of
course, is something like this:
return a > 3 ? 1 : 2;
HTH
Regards
--
Irrwahn Grausewitz (ir*******@freenet.de)
welcome to clc : http://www.ungerhu.com/jxh/clc.welcome.txt
clc faq-list : http://www.faqs.org/faqs/C-faq/faq/
acllc-c++ faq : http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html
我不确定你的意思。如果代码没有编译,则
函数根本不处于任何状态。
-
Keith Thompson(The_Other_Keith)< http://www.ghoti.net/~kst>
圣地亚哥超级计算机中心< *> < http://www.sdsc.edu/~kst>
Schroedinger做莎士比亚:要*和*不要
I''m not sure what you mean by this. If the code doesn''t compile, the
function isn''t in any state at all.
--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://www.sdsc.edu/~kst>
Schroedinger does Shakespeare: "To be *and* not to be"
这篇关于只想知道原因的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!