gpt4 book ai didi

c++ - C++中静态数组的类型和地址是什么?

转载 作者:可可西里 更新时间:2023-11-01 16:36:22 24 4
gpt4 key购买 nike

<分区>

使用 Visual Studio Express 2013。我以为我了解静态数组与动态数组,但以下内容让我感到困惑:

int* a = new int[3]; \\ dynamic array
int** pa = &a;

int b[3]; \\ static array
int** pb = &b; \\ error: cannot convert from 'int (*)[3]' to 'int **'

好的,所以我尝试 int (*)[3] pb = &b; 但它甚至在语法上都不正确。本地窗口说 pb 是一个 int[3],但是 int[3]* pb = &b; 也是不正确的。

enter image description here

bpa 的值相同,这对我来说似乎也很奇怪。如果我将声明 int b[3]; 替换为声明 + 初始化 int b[3] = {}; 那么奇怪的事情就会消失,所以也许它只是一个 VS错误:

enter image description here

但我仍然无法获取静态数组的地址。如果我在立即窗口中键入 &b,那么我得到的输出与我刚刚键入的输出完全相同 b,与 '&a' 和 'a' 相比,这又显得很奇怪这是明显不同的东西:

enter image description here

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