gpt4 book ai didi

c++ - 两个指针存储的信息不同

转载 作者:太空狗 更新时间:2023-10-29 20:31:23 25 4
gpt4 key购买 nike

是否真的有:

int* p = new int;

和:

int* p1 = new int[5]();

如果是 p1,会存储额外的信息吗?

最佳答案

是的,可能有。

我建议您阅读以下内容以了解 C++-faq 中的项目:

从第一个链接中提取的相关引用:

The run-time system stores the number of objects, n, somewhere where it can be retrieved if you only know the pointer, p. There are two popular techniques that do this. [...]

  • Over-allocate the array and put n just to the left of the first Fred object.
  • Use an associative array with p as the key and n as the value

关于c++ - 两个指针存储的信息不同,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4421148/

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