I am new to the C++ language and trying to complete a very simple code challenge to sum up all the numbers in an array. The test environment doesn't show an error message it only gives me an exit code 139. Upon some research this means my code is producing undefined behavior (also maybe memory fragmentation?). Is it just something with the syntax or is there something I'm missing about C++?
#include <vector>
int sum(std::vector<int> nums) {
int runningSum = 0;
for (int i=0; i <= nums.size(); i++) {
runningSum = runningSum + nums[i];
}
std::cout << "The total sum for nums: " << runningSum;
}