-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdebugging1.cpp
More file actions
51 lines (45 loc) · 1.38 KB
/
debugging1.cpp
File metadata and controls
51 lines (45 loc) · 1.38 KB
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
/**
* @file debugging1.cpp
* @author The CS2 TA Team <cs2tas@caltech.edu>
* @date 2014-2015
* @copyright This code is in the public domain.
*
* @brief An example of the utility of print statements in debugging.
*/
#include <iostream>
using namespace std;
/**
* @brief Does a thing.
*
* Does a thing, I dunno, you tell me.
*/
int main(int argc, char ** argv)
{
// Much of the following is intentionally undocumented.
// Part of the assignment is to figure out what is going on.
// You may need to look up some operators!
unsigned int a = 174, b = 85, x = 0;
// This construct is known as a 'while loop'.
// The interior of the loop is run if, and while,
// the given condition is true.
// The program proceeds past the loop if, and when,
// the given condition is found to be false just before any iteration
// of the interior of the loop.
while (b != 0)
{
// This construct is known as a conditional statement
// ('if' statement).
// The interior of the statement is run exactly once in its entirety
// if the given condition is found to be true.
// Note that 'true' is defined as nonzero,
// and 'false' is defined as zero.
if ((b & 1) != 0)
{
x += a;
}
a <<= 1;
b >>= 1;
}
// Question for you now: so what is x anyway?
return 0;
}