用C定义操作precedence [英] Operator precedence in C Definitions

查看:126
本文介绍了用C定义操作precedence的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

维基百科声称, [] 运算符precedes的 * 在评价经营者。

Wikipedia claims that the [] operator precedes the * operator in evaluation.

那么,为什么下面的语句:

Then, why does the following statement:

char *a[3];

申报的3字符指针数组,而不是一个指针的3个字符数组按照操作precedence?

declare an array of 3 character pointers, rather than a pointer to an array of 3 characters as per the operator precedence?

推荐答案

由于,如维基百科说, [] 具有较高的precedence比 *

Because, as Wikipedia says, [] has higher precedence than *?

处理的声明中, A [3] 被处理为3阵'你处理之前, *

Processing the declaration, the a[3] is processed as 'array of 3' before you process the *.

要声明一个指向三个字符数组,你必须用括号覆盖默认的precedence:

To declare a pointer to an array of three characters, you have to use parentheses to override the default precedence:

char (*a)[3];

现在括号采取阵列上precedence。

Now the parentheses take precedence over the array.

这篇关于用C定义操作precedence的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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