Initialize integer i as 0, what's the value of i after the following operation?i += i > 0 ? i++ : i--;
输出:-1
分析:
+=的优先级最低,所以i+=i>0?i++:i--直接将i>0?i++:i--的值也就是-1返回,i+=-1最后的结果是-1
具体过程:
i += i > 0 ? i++ : i--;
i+=i--
i=i+i--
i=-1+0
i=-1
发表于 2015-07