gpt4 book ai didi

c++ - 你如何破译指针+数组的复杂声明?

转载 作者:太空狗 更新时间:2023-10-29 19:45:05 24 4
gpt4 key购买 nike

虽然我几乎一直使用 std::vector,但我有兴趣尽可能多地了解指针。我正在谈论的例子:

char* array[5]; // What does it mean?
// 1) pointer to an array of 5 elements!
// 2) an array of 5 pointers?

我对这个声明的准确定义很感兴趣。

最佳答案

不仅仅是指针和数组:How to interpret complex C/C++ declarations :

Start reading the declaration from the innermost parentheses, go right, and then go left. When you encounter parentheses, the direction should be reversed. Once everything in the parentheses has been parsed, jump out of it. Continue till the whole declaration has been parsed.

One small change to the right-left rule: When you start reading the declaration for the first time, you have to start from the identifier, and not the innermost parentheses.

你的例子:

char* array[5];

是一个包含 5 个指向 char 的指针的数组。

关于c++ - 你如何破译指针+数组的复杂声明?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1501292/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com