如果不满足条件,这是否是重置计数器的有效/合理方式?这是我能想到的最紧凑的方式。
int counter = 0;
int a,b;
// Do .. and assign a and b
counter = ((a<b) ? counter++ : 0); 发布于 2015-08-25 15:37:43
您已经在分配给counter,所以也不要使用++。
counter = condition ? (counter + 1) : 0;发布于 2015-08-25 15:40:05
counter = (condition ? counter++ : 0);的行为是没有定义的,因为没有测序点。(三元没有排序,赋值也没有排序)。
它的形式类似于i = i++;
https://stackoverflow.com/questions/32208229
复制相似问题