0

I simply want to calculate this: "1039 * 3749 * 8473" in C++. I have tried long,long long, unsigned long long, nothing helps.

'''

int main(){
    unsigned long long int a;
    a = 1039 * 3749 * 8473;
    cout<< a<<endl;
    return 0;

'''

I get the following message(warning): test.cpp:8:21: warning: integer overflow in expression of type 'int' results in '-1355615565' [-Woverflow] 8 | a = 1039 * 3749 * 8473; | ~~~~~~~~~~~~^~~~~~ 18446744072353936051 Please help me resolve this, a test case is pending upon this.

  • suffix one of the literals with `ll` for long long, changing its type. All subexpressions (which are the 3 literals) currently have type int, which makes the whole expression to the right of the assignment operator having type int, which cannot hold the result. – Peter - Reinstate Monica Aug 16 '20 at 19:17
  • The type of an expression does not depend on what you assign it to, and since all the parts of `1039 * 3749 * 8473` are `int`s, the result is `int`. – molbdnilo Aug 16 '20 at 19:18

0 Answers0