如果我定义的2D阵列如:sizeof运算
char *tablechar[][2] = {
{"0", "Innova"},
{"2", "Brio" },
{"3", "Alto" },
{"4", "Bolero"},
{"5", "Swift" }
};
和代码在相同的文件中:
printf("Value = %d\n",sizeof(tablechar));
printf("Value = %d\n",sizeof(tablechar[0]));
printf("Num of rows = %d\n",sizeof(tablechar)/sizeof(tablechar[0]));
输出为预期:
Value = 40
Value = 8
Num of rows = 5
现在,我将这个2D矩阵传递给一个函数,其定义如下:
void printstuff(char *tab[][2])
{
printf("Value = %d\n",sizeof(tab));
printf("Value = %d\n",sizeof(tab[0]));
printf("Num of rows = %d\n",sizeof(tab)/sizeof(tab[0]));
}
我得到以下输出:
Value = 4
Value = 8
Num of rows = 0
与编译器警告在上面的功能:
为什么会这样认为的sizeof的值(标签)和sizeof(tablechar)不同?
4是指针的大小。 –
[如何找到'sizeof'(一个指向数组的指针)]]的可能的副本(http://stackoverflow.com/questions/492384/how-to-find-the-sizeofa-pointer-pointing-to -an-array) –
[C编程语言中数组的大小?](https://stackoverflow.com/questions/1975128/sizeof-an-array-in-the-c-programming-language?) – kaylum