I'm receiving a negative total when I run the code below (-294967296).
#include<iostream>
#include<vector>
#include<numeric>
using namespace std;
int main() {
vector<long long int> v={1000000000 , 1000000000 , 1000000000 , 1000000000};
cout<<"Sum of all the elements are:"<<endl;
cout<<accumulate(v.begin(),v.end(),0);
}
However, when I run the code below, I receive a positive sum (2000000000)
#include<iostream>
#include<vector>
#include<numeric>
using namespace std;
int main() {
vector<long long int> v={1000000000 , 1000000000};
cout<<"Sum of all the elements are:"<<endl;
cout<<accumulate(v.begin(),v.end(),0);
}
What may be the cause?