-
Notifications
You must be signed in to change notification settings - Fork 7
/
Drill 1,2
67 lines (51 loc) · 1.39 KB
/
Drill 1,2
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// -----------------------------------------------------------------------------
// https://lptcp.blogspot.com/
//
/*
Chapter 25
Drill 1
Run this:
int v = 1; for(int i = 0; i < sizeof(v)*8; ++i) { cout << v << ' '; v << =1; }
Drill 2
Run that again with v declared to be an unsigned int.
*/
// https://github.com/l-paz91/principles-practice/
// -----------------------------------------------------------------------------
//--INCLUDES--//
#include "std_lib_facilities.h"
// -----------------------------------------------------------------------------
void drill1()
{
int v = 1;
cout << "Max int: " << INT_MAX << "\n";
for (int i = 0; i < sizeof(v)*8; ++i)
{
cout << v << ' ';
v <<= 1;
}
}
// -----------------------------------------------------------------------------
void drill2()
{
unsigned int v = 1;
cout << "Max unsigned int: " << UINT_MAX << "\n";
for (int i = 0; i < sizeof(v) * 8; ++i)
{
cout << v << ' ';
v <<= 1;
}
}
// -----------------------------------------------------------------------------
int main()
{
drill1();
cout << "\n\n";
drill2();
cout << "\n\n";
pressKeyToContinue();
_CrtDumpMemoryLeaks();
return 0;
}
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------