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.

2
  • 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. Commented Aug 16, 2020 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 ints, the result is int. Commented Aug 16, 2020 at 19:18

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.