forked from jaege/Cpp-Primer-5th-Exercises
-
Notifications
You must be signed in to change notification settings - Fork 0
/
2.34.cpp
38 lines (34 loc) · 1014 Bytes
/
2.34.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
26
27
28
29
30
31
32
33
34
35
36
37
38
#include <iostream>
int main() {
int i = 0, &r = i;
const int ci = i, &cr = ci;
auto a = r; // int
auto b = ci; // int
auto c = cr; // int
auto d = &i; // int *
auto e = &ci; // const int *
const auto f = ci; // const int
auto &g = ci; // const int &
std::cout << "a: before = " << a;
a = 42; // OK
std::cout << "\tafter = " << a << std::endl;
std::cout << "b: before = " << b;
b = 42; // OK
std::cout << "\tafter = " << b << std::endl;
std::cout << "c: before = " << c;
c = 42; // OK
std::cout << "\tafter = " << c << std::endl;
std::cout << "d: before = " << d;
//d = 42; // Error
std::cout << "\tafter = " << d << std::endl;
std::cout << "e: before = " << e;
//e = 42; // Error
std::cout << "\tafter = " << e << std::endl;
std::cout << "f: before = " << f;
//f = 42; // Error
std::cout << "\tafter = " << f << std::endl;
std::cout << "g: before = " << g;
//g = 42; // Error
std::cout << "\tafter = " << g << std::endl;
return 0;
}