Why do I get an INT overflow error when assigning a long value to 'out[0]' in the following code? I have declared out as a vector already.
vector<long long> foo(int m, int n) {
vector<long long> out(5);
// why is there an overflow of int ??
out[0] = (m-1)*(n-1);
cout << out[0] << endl;
out[0] = (long long) (m-1)*(n-1);
cout << out[0] << endl;
..
..
return out;
}
I also found that typecasting the RHS works. But I'm not sure that is the intended way to assign 'long long' values.
COUT:
-615099295
3679868001
For values: m=40000 and n=92000
Please help me understand why I can't assign a value to the index normally, and what is the proper way of doing so. (I know this might be a newbie question, but I couldn't find much about this.)
I needed to assign values to this output vector using a map in my code, which I found out was returning garbage, and only after a good time spent debugging, I found a problem with the initial assignment itself.
Upon reviewing the SO related questions I found that LL needs to be mentioned after the number, but how do I do that with an expression of int variables?