2.9 整數溢位
¶什麼是溢位?
當一個算式算出來的結果,超過了它的型態能表示的範圍,就發生了溢位。
¶正向溢位
#include <iostream>
#include <climits>
using namespace std;
int main() {
int x = INT_MAX; // INT_MAX = 2,147,483,647
cout << "INT_MAX = " << x << endl;
cout << "INT_MAX + 1 = " << x + 1 << endl; // 溢位:通常印出負數
return 0;
}
Log in to read the full content
The syntax book is free for every AACPOJ account. Signing up takes a minute.