返回列表 發帖

陣列的長度

假設有一個陣列宣告如下:
int a[]= {5,4,3,7,6,5,9,8,3,4,2,1,5,3,5,7,8,1,3,4,3,2,6,7,9,6,6,9,0,4,5,6,5,1,7,8,7,9,6,0,2,5,6,7,9,3,4,0,9,8,6,1};

試運用 sizeof() 函式,求出該陣列的成員數量。
  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     int a[]= {5,4,3,7,6,5,9,8,3,4,2,1,5,3,5,7,8,1,3,4,3,2,6,7,9,6,6,9,0,4,5,6,5,1,7,8,7,9,6,0,2,5,6,7,9,3,4,0,9,8,6,1};
  7.     cout<<sizeof(a)/sizeof(int)<<endl;
  8.     system("pause");
  9.     return 0;
  10. }
複製代碼

返回列表