K12教育赛事综合服务平台
聚乐之家官方网站
下载聚乐之家官方App
专注青少年竞赛题库网站
已知C++数组int scores[] = {90, 85, 78, 92, 88};,需要遍历该数组并输出每个元素,要求避免数组越界且尽可能优化循环性能。
int scores[] = {90, 85, 78, 92, 88};
for(int i=0; i<=5; ++i) { cout << scores[i] << " "; }
for(int i=0; i<5; ++i) { cout << scores[i] << " "; }
int len = sizeof(scores)/sizeof(scores[0]); for(int i=0; i<len; ++i) { cout << scores[i] << " "; }
for(int i=1; i<=5; ++i) { cout << scores[i] << " "; }