Complete the tables that follow to describe the memory addresses and values of each variable when the last statement in the ChangePasscode function is performed (right before the function exits). Note: Operating systems may use different rules for assigning memory addresses. For this worksheet let us assume that the compiler will use up the greater memory address first (e.g., if 0x7ffd151a1d58 and 0x7ffd151a1d5c are available, it will initialize variables in 0x7ffd151a1d5c first). #include // Changes the passcode to new_passcode if // verify_passcode matches the old passcode. bool ChangePasscode(int& passcode, int verify_passcode, int new_passcode) { if (verify_passcode == passcode) { passcode = new_passcode; return true; } else { return false; } } int main() { int passcode = 112233; int verify_passcode = 0; int new_passcode = 0; std::cout << "Please enter old passcode: "; std::cin >> verify_passcode; // user enters 112233 std::cout << "Please enter new passcode: "; std::cin >> new_passcode; // user enters 456789 bool changed_passcode = ChangePasscode(passcode, verify_passcode, new_passcode); if (changed_passcode) { std::cout << "Passcode changed."; } else { std::cout << "Passcode remains the same.\n"; } return 0; } Output: Please enter old passcode: 112233 Please enter new passcode: 456789 Passcode changed
Complete the tables that follow to describe the memory addresses and values of each variable when the last statement in the ChangePasscode function is performed (right before the function exits). Note:
#include <iostream>
// Changes the passcode to new_passcode if
// verify_passcode matches the old passcode.
bool ChangePasscode(int& passcode, int verify_passcode,
int new_passcode) {
if (verify_passcode == passcode) {
passcode = new_passcode;
return true;
} else {
return false;
}
}
int main() {
int passcode = 112233;
int verify_passcode = 0;
int new_passcode = 0;
std::cout << "Please enter old passcode: ";
std::cin >> verify_passcode; // user enters 112233
std::cout << "Please enter new passcode: ";
std::cin >> new_passcode; // user enters 456789
bool changed_passcode = ChangePasscode(passcode,
verify_passcode,
new_passcode);
if (changed_passcode) {
std::cout << "Passcode changed.";
} else {
std::cout << "Passcode remains the same.\n";
}
return 0;
}
Output:
Please enter old passcode: 112233
Please enter new passcode: 456789
Passcode changed
Trending now
This is a popular solution!
Step by step
Solved in 2 steps