Board logo

標題: 陣列的長度 [打印本頁]

作者: 鄭繼威    時間: 2024-1-8 17:54     標題: 陣列的長度

假設有一個陣列宣告如下:
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. }
複製代碼





歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://seed.istak.org.tw/) Powered by Discuz! 7.2