数组名和指针相同吗?
December 4, 2012
C
/*
数组名和指针相同吗?
*/
#include <iostream>
#include <cstdlib>
#include <cstdio>
using namespace std;
int a[][3] = {{1, 2, 3}, {1, 2, 3}, {4, 5, 6}, {3, 4, 5}};
int sizef(int b[][3])
{
cout << sizeof(b) << endl;
cout << sizeof(b[0]) << endl;
cout << sizeof(b)/sizeof(b[0]) << endl;
}
int main(void)
{
// int a[][3] = {{1, 2, 3}, {1, 2, 3}, {4, 5, 6}, {3, 4, 5}};
cout << sizeof(a) << endl;
cout << sizeof(a[0]) << endl;
cout << sizeof(a)/sizeof(a[0]) << endl;
cout << "***********" << endl;
sizef(a);
// cout << sizef(a) << endl;
system("pause");
return 0;
}
上面的程序的结果是: 48 12 4
4 12 0