passarray.cpp

来自「C++ sample code, for the book: C++ blac」· C++ 代码 · 共 25 行

CPP
25
字号
#include <iostream>
using namespace std;

long adder(int array[], int number_elements);

int main()
{
    int data[] = {1, 2, 3, 4};

    int total = adder(data, sizeof(data)/sizeof(int));

    cout << "The total is " << total << endl;

    return 0;
}

long adder(int array[], int number_elements)
{
    long sum = 0;                   

    for (int loop_index = 0; loop_index < number_elements; loop_index++)
        sum = sum + array[loop_index];

    return sum;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?