79459406

Date: 2025-02-22 10:13:17
Score: 0.5
Natty:
Report link

Smaller data types like short int, char which take less number of bytes gets promoted to int or unsigned int as per C++ standard. But not the larger sized data types. This is called Integer promotions.

You can explicitly cast it to a larger type before performing the multiplication(or any arithmetic operation) to avoid this over flow like this:

#include <iostream>
int main()
{
    int ax = 1000000000;
    int bx = 2000000000;
    long long cx = static_cast<long long>(ax) * bx;
    std::cout << cx << "\n";
    return 0;
}

It will ensure the correct output as 2000000000000000000.

Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Filler text (0.5): 000000000000000000
  • Low reputation (1):
Posted by: AmitJhaIITBHU