第29345题 单选题
下列关于C++循环结构与边界优化的说法中,正确的是哪一项?

以下有两段C++代码片段供参考:

  1. 计算数组前n个元素和的函数:
    int calculateSum(int arr[], int n) {
     int sum = 0;
     for(int i = 0; i <= n; ++i) {
         sum += arr[i];
     }
     return sum;
    }
  2. 遍历数组打印元素的函数:
    void printElements(int arr[], int len) {
     for(int i = 0; i < len; ++i) {
         std::cout << arr[i] * 4 - 1 << std::endl;
     }
    }
{{ option.label }}
子题{{ index + 1 }} {{ child.type_label }}
{{ option.label }}
✓ 正确 ◐ 部分正确 ✗ 错误
程序运行统计
暂无判题统计
提交{{ questionInfo.stats ? questionInfo.stats.submit_count : 0 }}次 正确率{{ statsAccuracy }}%
答案解析