求数组长度

char str1[11] = "Hello";
int size = sizeof(str1) / sizeof(char);
//打印11
cout << "str1.array.size=" << size << endl;

分配内存

short shortarray[10] = {};
int intarray[10] = {};
long longarray[10] = {};
long long longlongarray[10] = {};

// 20 字节
cout << "shortarray.size" << sizeof(shortarray) << endl;
// 40
cout << "intarray.size" << sizeof(intarray) << endl;
// 40
cout << "longarray.size" << sizeof(longarray) << endl;
// 80
cout << "longlongarray.size" << sizeof(longlongarray) << endl;