1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
|
| int main() { char str1[] = "1234"; cout << sizeof(str1) << endl; //5 char str2[6] = "1234"; cout << sizeof(str2) << endl; //6 int array1[] = {1,2,3,4}; cout << sizeof(array1) << endl; //16 int array2[6] = {1,2,3,4}; cout << sizeof(array2) << endl; //24 return 0; }
|
掌握核心sizeof是所占内存的大小,或者说申请内存的大小。