In my case, the product of two INT_MAX numbers is equal 296447233, which is wrong.
296447233
long long int product = 0; product = 2137483647 * 2137483647; printf("product: %lli\n", product);
What am I doing wrong and how to fix it ?? Thank!
Both of 2137483647are of type int. Thus, they retain this type and overflow.
2137483647
int
Make them long longs:
long long
product = 2137483647LL * 2137483647LL;
or cast:
product = (long long)2137483647 * 2137483647;
Try
for the compiler to process numbers for how long are long