In my case, product of two INT_MAX numbers is 296447233
, which is incorrect.
long long int product = 0;
product = 2137483647 * 2137483647;
printf("product: %lli\n", product);
What I am doing wrong, and how to correct it ?? Thanks !
Both of your 2137483647
are of type int
. So they stay that type and overflow.
Make them long long
s:
product = 2137483647LL * 2137483647LL;
or cast:
product = (long long)2137483647 * 2137483647;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With