c++ - sizeof 运算符和多维表

标签 c++ sizeof

我遇到了一个问题,因为我不知道 sizeof 运算符是如何工作的。谁能告诉我为什么它在下面的代码中给了我 4?

int tab[2] = {1, 5};
int *filePathTab[1] = {NULL};
filePathTab[0] = tab;
cout << sizeof(filePathTab[0]);

最佳答案

filePathTab[0] 有一个 int * 作为它的元素。您机器上的 sizeofint * 是 4 个字节。如果你想知道 sizeof int * 指向什么,一个 int,你必须取消引用指针:

cout << sizeof(*filePathTab[0]);

结果可能是您机器上的 sizeofint 也是 4 个字节。

关于c++ - sizeof 运算符和多维表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21029104/

相关文章:

c++ - 在 C++ (linux) 中设置 GPIO 的最快方法

c++ - 如何使用 msxml4 为 child 获取 xml 字符串?

c++ - 使用 goto 转义控制结构是否会产生不同的程序集?

c - sizeof union 大于预期。这里如何进行类型对齐?

c - sizeof (function(argument)) 返回什么?

c++ - 带有 "source shellscript.sh"的 CLion

c - 为什么 sizeof 运算符对某些表达式的工作方式不同?

c - 在 C 中存储 char* 数组

java - Java 对象的大小

c# - UWP 和 DirectX