我目前正在參加C++課程,我們正在學習指針。以下是我的教授給我們的例子。Sizeof運算符來測量二維數組
int b[3][3]; //Assume integers and memory addresses are 4 bytes
cout << sizeof(b) << endl; // 36 bytes
cout << sizeof(b+0) << endl; // 4 bytes
cout << sizeof(*(b+0)) << endl; //12 bytes
我有2個問題:
我想第二個(
sizeof(b+0)
),它給了我8呢?情況如何?另外我想了解第三個邏輯背後的邏輯(
sizeof(*(b+0)
);是12,因爲它是第一排的總數?由於有3個int,每個int都是4個字節,因此總共返回12個字節?
任何幫助非常感謝!
C與C++不一樣;您應該刪除C標記 – Miket25
sizeof不是函數。它是關鍵字。 – ikh