为V [我++]未定义用C? [英] Is v[i++] undefined in C?

查看:89
本文介绍了为V [我++]未定义用C?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想code,它通过字符检查一个函数*一个[] ,而且往往最终会使用类似

I'm trying to code a function that checks a through a char* a[], and often end up using something like

if(a[i] == 'x'){
    i++;
    //...
}

现在我真的想改变这 A [我++] 代替,但它似乎并没有工作。

Now I would really like to change this to a[i++] instead, but it doesn't seem to work.

问:

难道我在这里做得不对,或者是有一个清洁的替代,以避免我++

Am I doing something wrong here, or is there a clean alternative to avoid the i++?

请注意:目前我在功能13排3是我++ ,这使得它看起来显著大于它确实是。

Note: Currently 3 of my 13 rows in the function are i++, which makes it look significantly larger than it really is.

推荐答案

如果(A [++] =='X')本身是C.它细然而,语义不同:您原来的code仅增加 I 如果条件为真,而如果(A [++] == 'X')总是增加 I

if (a[i++] == 'x') by itself is fine in C. It is, however, semantically different: Your original code only increments i if the condition is true, whereas if (a[i++] == 'x') always increments i.

这篇关于为V [我++]未定义用C?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆