gpt4 book ai didi

c - 数组的区别和名称

转载 作者:行者123 更新时间:2023-11-30 20:14:04 24 4
gpt4 key购买 nike

数组声明int *a[20]有什么区别, int a[20] , int (*a)[20]

它们的名字是什么以及它们如何在编程中应用?在前两种情况下编写 *a++ 会给出错误以及 a++ ,而第三种情况则不会?为什么?

最佳答案

int *a[20];

a 是 20 个指针的数组

int a[20];

a 是 20 个 int 元素的数组

int (*a)[20];

a 是指向 20 个 int 元素的数组的指针

编辑:

当您有 a++ 时,其中 a 是一个数组,那么这相当于 a= a + 1; 并且根据以下标准数组名称不能是可修改的左值。

A modifiable lvalue is an lvalue that does not have array type, does not have an incomplete type, does not have a const-qualified type, and if it is a structure or union, does not have any member (including, recursively, any member or element of all contained aggregates or unions) with a const-qualified type.

关于c - 数组的区别和名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28008239/

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