Check out example codes for "sum elements in vector c++". It will help you in understanding the concepts better.

Code Example 1

accumulate(a.begin(), a.end(), 0)

Code Example 2

for (auto& n : vector)
    sum_of_elems += n;

Code Example 3

accumulate(a.begin(), a.end(), 0);

Learn ReactJs, React Native from akashmittal.com