本文介绍了++ val的解释++和++ * p ++用C的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

int val = 5;

printf("%d",++val++); //gives compilation error : '++' needs l-value

int *p = &val;
printf("%d",++*p++); //no error

有人能解释一下这两个案例?谢谢你。

Could someone explain these 2 cases? Thanks.

推荐答案

++ VAL ++ 相同 ++(VAL ++)。由于 VAL ++的结果不是左值,这是非法的。正如斯蒂芬佳能指出,如果结果 VAL ++ 是一个左值, ++(VAL ++)将是不确定的行为还有就是 ++ 秒之间没有顺序点。

++val++ is the same as ++(val++). Since the result of val++ is not an lvalue, this is illegal. And as Stephen Canon pointed out, if the result of val++ were an lvalue, ++(val++) would be undefined behavior as there is no sequence point between the ++s.

++ * P ++ 相同 ++(*(P ++))。由于 *(P ++)的结果的左值,这是合法的。

++*p++ is the same as ++(*(p++)). Since the result of *(p++) is an lvalue, this is legal.

这篇关于++ val的解释++和++ * p ++用C的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 11:00