From 6ccd1ef578ff6d251adf9ae3743af065cbeaa977 Mon Sep 17 00:00:00 2001 From: Trevor Bouchillon Date: Sun, 16 Oct 2022 15:29:38 -0700 Subject: Exercise 1 done --- CST116-Ch9-Debugging/CST116-Ch9-Debugging.cpp | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) (limited to 'CST116-Ch9-Debugging') diff --git a/CST116-Ch9-Debugging/CST116-Ch9-Debugging.cpp b/CST116-Ch9-Debugging/CST116-Ch9-Debugging.cpp index eff8980..88caf88 100644 --- a/CST116-Ch9-Debugging/CST116-Ch9-Debugging.cpp +++ b/CST116-Ch9-Debugging/CST116-Ch9-Debugging.cpp @@ -4,6 +4,9 @@ * General Instructions: Complete each step before proceeding to the * next. * +* Trevor Bouchillon +* Debugging Ch9 +* * Debugging Exercise 1 * * 1) Insert a breakpoint on the lines indicated in the code. @@ -12,15 +15,24 @@ * 4) Add another watch using &age for the name. This will display * the address of age. * 5) Write down the address of age. +* **************************************************************************************************************** +* 0x000000678a15f9d4{0} +* **************************************************************************************************************** * 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 variable for age was defined a second time, this time without a defining value. This assigns it a space in memory and assigns the variable whatever is already in that memory location. +* **************************************************************************************************************** * 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? +* **************************************************************************************************************** +* Because the variable is defined as zero in main, and redefined in the fuction getage. +* **************************************************************************************************************** * 15) Stop debugging and fix the error. * 16) Run to Breakpoint 1. * 17) Step over the function call to GetAge. @@ -69,12 +81,11 @@ const int DAYS_PER_YEAR = 365; int GetAge(); int CalcDays(int age); void PrintResults(int age, int days); +int days = 0; +int age; int main() { - int age = 0; - int days = 0; - // Breakpoint 1 // Put breakpoint on the following line GetAge(); @@ -88,8 +99,6 @@ int main() } int GetAge() { - int age; - cout << "Please enter your age: "; cin >> age; -- cgit v1.2.3