C++ 星号和括号运算符一起使用

标签 c++ operators

抱歉标题很蹩脚,但我不知道如何更好地描述这个问题。

什么意思:

int (*x)[];

以及如何初始化它?

我知道它不是 int *x[] 因为:

int a,b;
int (*x)[] = {&a, &b};

不会编译。

提前谢谢你。

最佳答案

类型声明具有类似表达式的语法,因此您可以将它们解析为 你会表达:

      x       x is
     *x       a pointer
    (*x)[]    to an array of unknown dimensions
int (*x)[]    of int

优先规则是右边的运算符比 左边的那些,在每种情况下,操作符都离元素更近 绑定(bind)更紧密,最后,括号可以用来改变这些 绑定(bind),所以:

int  *x[];    is an array of pointers,
int *(x[]);   as is this.
int (*x)[];   whereas here, the parentheses change the bindings.

关于C++ 星号和括号运算符一起使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10350461/

相关文章:

c++ - 如何测试stringstream operator>>是否解析了错误的类型并跳过它

c++ - 防止滥用逻辑运算符而不是按位运算符

c# - 空合并运算符是否有 "opposite"? (……用任何语言?)

c++ - 如何在 log(n) 时间内找到数组任意范围内的最大值?

c++ - 模板推导 : const reference and const pointer

C++指针多继承的乐趣

C++ 输出错误(新增问题)

scala - 在 Scala 中使用运算符 orElse 的正确方法是什么?

c++ - c++中的数字加法

ruby - 如何在 Ruby 中定义复合运算符(例如 +=)?