C ++运算符优先级=,*和++ [英] C++ Operator priority =, * and ++

查看:190
本文介绍了C ++运算符优先级=,*和++的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对这个指针值分配有疑问:

I have a question with this pointer value assignment:

*p++ = *q++;

根据 运营商优先级表

运算符的优先级为"++">"*">"=".

The priorities of operators are "++" > "*" > "=".

但是上述语句的结果首先执行赋值"=",如下所示

But the result of the above statement does the assignment "=" first, as the following

*p = *q;
p++;
q++; 

为什么?

推荐答案

后递增运算符在其值已经计算之后,将其操作数递增.因此,指针的引用发生在指针的值上在这条线之前举行.但是,您给出的优先级是正确的.该表达式确实等同于

The post-increment operator increments its operand after its value has already been computed. The pointer dereference therefore occurs on the values the pointers held before this line. However, the precedence you give is correct; the expression is indeed equivalent to

(*(p++)) = (*(q++))

这篇关于C ++运算符优先级=,*和++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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