为什么* PTR ++的行为,如*(PTR ++),而不是(* PTR)++? [英] why does *ptr++ act like *(ptr++) and not (*ptr)++?

查看:204
本文介绍了为什么* PTR ++的行为,如*(PTR ++),而不是(* PTR)++?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:结果
   ++上在C中取消引用指针?

同样的,会是什么
* PTR + = 1
* ptr的%8,和
* PTR / 8
是什么?

Similarly, what would *ptr += 1 *ptr % 8, and *ptr / 8 be?

的差异显得扑朔迷离。
是这样的,也许,编译器相关的?

The differences seem confusing. Is this, perhaps, compiler dependent?

推荐答案

它与运营商precedence做。在 * 所以最后出现操作者具有较低的precedence比 ++

It has to do with operator precedence. The * operator has a lower precedence than ++ so it occurs last.

下面是一个维基百科图表,列出了所有的运营商: HTTP: //en.wikipedia.org/wiki/Operators_in_C_and_C%2B%2B#Operator_$p$pcedence

Here's a Wikipedia chart that lists all the operators: http://en.wikipedia.org/wiki/Operators_in_C_and_C%2B%2B#Operator_precedence

您可以在图表中看到,后缀 ++ 有2 precedence而 * 取消引用有3. precedence(数字略有倒退,因为较低的数字有较高的precedence)。

You can see in the chart that postfix ++ has a precedence of 2 while * dereference has a precedence of 3. (The numbers are slightly backwards, as lower numbers have higher precedence).

这篇关于为什么* PTR ++的行为,如*(PTR ++),而不是(* PTR)++?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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