C++ 矩阵大小始终返回8

C++ 矩阵大小始终返回8,c++,multidimensional-array,C++,Multidimensional Array,在下面的代码中,我想找到2d arraymatrix的大小,然而,当我尝试这样做时,尽管在测试之前我被声明为矩阵的大小,但它总是输出1。FactoryMatrix和FactoryMatrix[0]的大小看起来和8相同。你知道这是什么原因吗?谢谢 factorMatrix = new int* [3]; for(i=0; i<3; i++) { /**/ factorMatrix[i] = new int [1]; } fact

在下面的代码中,我想找到2d arraymatrix的大小,然而,当我尝试这样做时,尽管在测试之前我被声明为矩阵的大小,但它总是输出1。FactoryMatrix和FactoryMatrix[0]的大小看起来和8相同。你知道这是什么原因吗?谢谢

factorMatrix = new int* [3];
    for(i=0; i<3; i++)
    {
        /**/
        factorMatrix[i] = new int [1];
    }   

factorCountMatrix = new int* [3];
    for(i=0; i<3; i++)
    {
        /**/
        factorCountMatrix[i] = new int [1];
    }

factorMatrix[0][0] = 2;
factorCountMatrix[0][0]= 0;

factorMatrix[1][0] = 3;
factorCountMatrix[1][0]= 0;

factorMatrix[2][0] = 5;
factorCountMatrix[2][0]= 0;

//test = checkFactorMatrix(3);
test = (sizeof(factorCountMatrix) / sizeof(factorCountMatrix[0]));
cout <<  test << endl << endl;

在指针上使用sizeof运算符时,得到的是指针的大小,而不是指针指向的内容。您需要跟踪自己分配的内存大小,或者使用类似或我推荐的其他方法。

factorCountMatrix和factorCountMatrix[0]都是指针,因此它们的大小相同,可以告诉您类型的大小,即int*的大小。两天前您对a的回答是否相同?