Integer overflow takes place even if I type cast to long int (C++)

I am trying to understand the phenomenon of overflow and decided to demonstrate the same by executing the piece of code provided below:

#include <bits/stdc++.h>

using namespace std;

int main(){
    int a = 100000;
    int b = 100000;
    cout << a * b << endl; 
    long int c = a * 1LL * b;
    cout << c;
    return 0;
} 

The idea is that simply multiplying a and b (as done in line 6) would result in an integer overflow as 10^10 falls outside the range of the integer data type. To overcome this, the product (a*b) is multiplied with the literal ‘1LL’ (as shown in line 7).
The problem is that integer overflow still takes place as the output of the program is:

1410065408
1410065408

It’s possible that I am making a super silly mistake somewhere, but I have spent a sufficient amount of time trying to understand where it’s going wrong and am yet to find the reason. Hoping for some help/guidance here 🙂

Read more here: Source link