標題:
陣列的長度
[打印本頁]
作者:
鄭繼威
時間:
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()
函式,求出該陣列的成員數量。
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
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};
cout<<sizeof(a)/sizeof(int)<<endl;
system("pause");
return 0;
}
複製代碼
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://istak.org.tw/seed/)
Powered by Discuz! 7.2