diff options
| author | Andrei F <[email protected]> | 2022-10-19 20:49:41 -0700 |
|---|---|---|
| committer | Andrei F <[email protected]> | 2022-10-19 20:49:41 -0700 |
| commit | df255bcebe1fd7aaf500892f3ae31bd27e2221af (patch) | |
| tree | ef5a03b9a51dfc706f61e92340ea515c0961cf4b /CST116-Ch9-Debugging/CST116-Ch9-Debugging.cpp | |
| parent | Finished chapter9 questions (diff) | |
| download | cst116-ch9-debugging-florea-df255bcebe1fd7aaf500892f3ae31bd27e2221af.tar.xz cst116-ch9-debugging-florea-df255bcebe1fd7aaf500892f3ae31bd27e2221af.zip | |
Finished exercise 1 & 2
Diffstat (limited to 'CST116-Ch9-Debugging/CST116-Ch9-Debugging.cpp')
| -rw-r--r-- | CST116-Ch9-Debugging/CST116-Ch9-Debugging.cpp | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/CST116-Ch9-Debugging/CST116-Ch9-Debugging.cpp b/CST116-Ch9-Debugging/CST116-Ch9-Debugging.cpp index 90127a3..b7c36e3 100644 --- a/CST116-Ch9-Debugging/CST116-Ch9-Debugging.cpp +++ b/CST116-Ch9-Debugging/CST116-Ch9-Debugging.cpp @@ -27,21 +27,35 @@ * 4) Add another watch using &age for the name. This will display
* the address of age.
* 5) Write down the address of age.
+ *
+ * 0x000000016dd67838
+ *
* 6) Step Into the code for the function GetAge.
* 7) The execution continues to the function header for GetAge.
* 8) Step into one more time.
* 9) Why did the address of age and value change?
+ *
+ * The address of age and its value changed because we entered a function, where it initialized
+ * a new variable with the same name, and gave it a different value. It is not overwriting the
+ * original age variable, it is instead creating a new variable.
+ *
* 10) Step over the cout and cin statements.
* 11) Verify the value entered is stored properly in age.
* 12) Step into until the flow returns to main.
* 13) Step over one more time.
* 14) Why didn't the value entered get transferred back to main?
+ *
+ * The value entered didn't get transferred back to main because we are not
+ * storing the return value of GetAge() to the variable age.
+ *
* 15) Stop debugging and fix the error.
* 16) Run to Breakpoint 1.
* 17) Step over the function call to GetAge.
* 18) Verify that the value entered was returned and stored
* correctly from GetAge.
* 19) Stop debugging.
+ *
+ * Done.
*
* Debugging Exercise 2
*
@@ -51,6 +65,11 @@ * 4) Step into one more time so that the current line is the
* calculation.
* 5) Why is age greyed out in your watch window?
+ *
+ * I believe age is greyed out in my watch window because we are not using the variable age to
+ * calculate the amount of days. It is now using the newly initialized variable in the parameter of
+ * CalcDays() which is "int years". So instead of age, I have years in my watch window.
+ *
* 6) Stop debugging.
*
* Debugging Exercise 3
@@ -92,7 +111,7 @@ int main() // Breakpoint 1
// Put breakpoint on the following line
- GetAge();
+ age = GetAge();
days = CalcDays(age);
// Breakpoint 2
|