小编Tan*_*llo的帖子

C++ 数组和指针的 sizeof 结果

在 x86_64 架构上,一个指针是 8 个字节。对我来说sizeof(x)应该返回 8是有意义的。我知道 achar是单个字节,而 5 个字节是 array 的大小z。为什么sizeof(z)不返回8背后的直觉是什么?

int* x = new int[10];
char z[5];

// Returns 8
std::cout << "This is the size of x: " << sizeof(x) << std::endl;

// Returns 5
std::cout << "This is the size of z: " << sizeof(z) << std::endl;
Run Code Online (Sandbox Code Playgroud)

c++ pointers internal-representation abstract-machine

7
推荐指数
1
解决办法
121
查看次数