Adding numbers larger than long long in C++

前端 未结 4 1549
庸人自扰
庸人自扰 2020-12-20 10:26

I want to add two numbers which is the largest values that a long long integer can hold; and print it. If I don\'t store the value of sum in a variable, I just print it usin

4条回答
  •  礼貌的吻别
    2020-12-20 11:03

    Since long long is signed, the addition overflows. This is Undefined Behavior and anything may happen. It's unlikely to format your harddisk, especially in this simple case.

    Once Undefined Behavior happens, you can't even count on std::cout working after that.

提交回复
热议问题