can you explain why i am getting an integer overflow in first code but not in second?
#include<bits/stdc++.h>
using namespace std;
#define ch "\n"
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long int g = (1000000 * 2) * 1000000;
// long long int k = f * 1000000;
cout << g % 10000003;
return 0;
}
'''
#include<bits/stdc++.h>
using namespace std;
#define ch "\n"
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long int f = 1000000 * 2;
long long int k = f * 1000000;
cout << k % 10000003;
return 0;
}
second code is giving correct output while first is showing error. error is shown below.
warning: integer overflow in expression of type 'int' results in '-1454759936' [-Woverflow]
8 | long long int g = (1000000 * 2) * 1000000;
| ~~~~~~~~~~~~~~^~~~~~~~~
[Finished in 0.8s]