http://www.includehelp.com/c/operators-aptitude-questions-and-answers.aspx 3) What will be the output of following program ? #include void main() { int x=10; x+=(x++)+(++x)+x; printf("%d",x); } 1. 44 2. 45 3. 46 4. 47 Correct Answer - 2 45 1) expand the expression : x=x+(x++)+(++x)+x; 2) due to pre increment ++x , x will be 11 for this expression. 3) after executing expression x will be 44. 4) finally x will be 45 due to post increment (x++). 弄不懂呀,到底这里 ++x, x++哪个先算?觉得x++应该先算,因为它先出现。可是解 释的正好相反。 我在电脑上编译run了一下这个代码,输出的就是45. 可是解释不通呀, 谁给看看。多谢 过去一直觉得对+这样的运算符都是从左到右。这题彻底颠覆了俺学了/用了几十年的 C语言的基本常识。很悲催呀。
My case is same as yours, applied in August. Can not even find the case in their online system. Called them and they said they are going to mail it. But now I've got my green card already. So I don't bother with this anymore. Just thought I lost $680 to USCIS. That is two iPhone 4S, wuwu.
还有就是同个link里的这个题 11) What will be the output of following program ? #include int main(){ char val=250; int ans; ans= val+ !val + ~val + ++val; printf("%d",ans); return 0; } Correct Answer - 2 -6 250 is beyond the range of char, the value of val will be -6. Consider the expression: ans= val+ !val + ~val + ++val; Operator! , ~ and ++ have equal precedence. And it associative is right to left. So, First ++ operator will perform the operation. So value val will -5 Now, ans = -5 + !-5 + ~-5 + -5 = -5 + !-5 + 4 - 5 = -5 + 0 + 4 -5 = -6 感觉怎么是从右往左算的呀?太坑爹了。
: 11) What will be the output of following program ?
: #include
: int main(){
: char val=250;
: int ans;
: ans= val !val ~val val;
: printf("%d",ans);
: return 0;
: }
【在 c*********t 的大作中提到】 : 还有就是同个link里的这个题 : 11) What will be the output of following program ? : #include : int main(){ : char val=250; : int ans; : ans= val+ !val + ~val + ++val; : printf("%d",ans); : return 0; : }
m*q
15 楼
2011 + 4 应该是2015吧。 谢谢!
【在 w******t 的大作中提到】 : 2015年10月前。 : : 我妈妈去年十月签证,通过后有拿到一张纸条说,一年内再签,可以免面谈如果我妈明 : 年过来,是不是一定要在今年十月前签证才能免面谈呢? : ★ Sent from iPhone App: iReader Mitbbs Lite 7.56
l*m
16 楼
如果用gcc编译,结果是46. 第二行是45. x += (x++)+(++x)+x; 46 x = x+(x++)+(++x)+x; 45 x = (x++)+(++x)+x+x; 46 用clang,结果是46. 第二行是44, x += (x++)+(++x)+x; 46 x = x+(x++)+(++x)+x; 44 x = (x++)+(++x)+x+x; 46 用VC++,全是45。 pre inc当然先算了。只是不同的compiler处理sequence point时有小小差别。