小编use*_*484的帖子

为什么sizeof()我的双数组[4]只有4?

我正在尝试编写一个遍历数组中所有元素的循环.我在这里学到了这个概念.我的执行面临一些困难.我一直在尝试调试,我已经编写了以下函数作为调试过程的一部分.以下是我的代码:

#include <iostream>
using namespace std;

struct Vmul {
    double c[4][4];
};
double Vmulti(double a[4], double d[4]) {
    cout << sizeof(a) << endl;
    cout << sizeof(a[0]) << endl;
    cout << sizeof(a)/ sizeof(a[0]) << endl;
    return 0;
}
int main()
{
    double r[4] = { 1,2,3,4 };
    double q[4] = { 1,2,3,4 };
    Vmulti(r, q);
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

输出:

4
8
0
Press any key to continue . . .
Run Code Online (Sandbox Code Playgroud)

我无法弄清楚为什么sizeof(a)只返回4?不应该是8*4吗?为什么sizeof不给我大小而是给我数组中的元素数量?

c++ arrays sizeof

0
推荐指数
1
解决办法
135
查看次数

标签 统计

arrays ×1

c++ ×1

sizeof ×1