c – 三元运算符和增量运算符
发布时间:2020-12-16 10:11:51 所属栏目:百科 来源:网络整理
导读:如果不满足条件,这是重置计数器的有效/合理方式吗?这是我能想到的最紧凑的方式. int counter = 0;int a,b;// Do .. and assign a and b counter = ((ab) ? counter++ : 0); 解决方法 您已经分配到计数器,所以不要使用. counter = condition ? (counter + 1)
如果不满足条件,这是重置计数器的有效/合理方式吗?这是我能想到的最紧凑的方式.
int counter = 0; int a,b; // Do .. and assign a and b counter = ((a<b) ? counter++ : 0); 解决方法
您已经分配到计数器,所以不要使用.
counter = condition ? (counter + 1) : 0; (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |