混合增量运营商逻辑运算符 [英] Mixed increment operators with logical operators
问题描述
我有关于与逻辑运算符pre和后增量的问题
如果我有这样的code
I have a question concerning pre and post increments with logical operators if I have this code
void main()
{int i = - 3 , j = 2 , k = 0 , m ;
m=++i||++j&&++k;
printf("%d %d %d %d",i,j,k,m);}
知道递增和递减运营商有更高的precedence比&安培;&安培;和||
因此,他们会先执行然后和放大器;&安培;比结果高
装置-2 || 3和;&放大器; 1,它给出的值-2 3 1 1为printf的
knowing that the increment and the decrement operators have higher precedence than && and ||
So they'll be executed first Then the && is higher than
means -2||3&&1 which gives the values -2 3 1 1 for the printf
但输出上VS2010努力时,我得到的是-2 2 0 1
but the output I get when trying on VS2010 is -2 2 0 1
有没有人有任何的解释?
问候,,
Does anyone have any explanation for that ? Regards,,
推荐答案
这是你从短路得到什么。 + I
为-2,其余不必进行评估(并且不按照标准)。左侧 ||
是真实的,因为-2不为0,因此整个前pression是真实的。
This is what you get from short circuiting. ++i
is -2, and the rest doesn't have to be evaluated (and isn't according to the standard). The left side of ||
is true because -2 is not 0, so the whole expression is true.
这篇关于混合增量运营商逻辑运算符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!