forked from jaege/Cpp-Primer-5th-Exercises
-
Notifications
You must be signed in to change notification settings - Fork 0
/
2.4.cpp
25 lines (20 loc) · 832 Bytes
/
2.4.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include <iostream>
int main() {
unsigned u = 10, u2 = 42;
std::cout << u2 - u << std::endl; // 32
std::cout << u - u2 << std::endl; // 4294967264 = -32 + 4,294,967,296
int i = 10, i2 = 42;
std::cout << i2 - i << std::endl; // 32
std::cout << i - i2 << std::endl; // -32
std::cout << i - u << std::endl; // 0
std::cout << u - i << std::endl; // 0
// Mix unsigned with signed.
std::cout << i - u2 << std::endl; // 4294967264 = -32 + 4,294,967,296
std::cout << u2 - i << std::endl; // 32
std::cout << i2 - u << std::endl; // 32
std::cout << u - i2 << std::endl; // 4294967264 = -32 + 4,294,967,296
int i3 = -10;
std::cout << i3 + u << std::endl; // 0 = -10 + 4,294,967,296 + 10 - 4,294,967,296
std::cout << i3 - u << std::endl; // 4294967276 = -10 + 4,294,967,296 - 10
return 0;
}