Question 11
Back to Exercise
What is the output of the following C++ program?
#include <iostream>
int rate = 5;
int interest(int amount, int r = rate) { return amount * r / 100; }
int main() {
std::cout << interest(1000) << ' ';
rate = 8;
std::cout << interest(1000) << ' ' << interest(1000, 10) << '\n';
return 0;
}
- A 50 80 100 Correct
- B 50 50 100
- C 80 80 100
- D 50 80 80
Correct Answer: Option A
A default argument expression is evaluated at every call, so it sees the current value of rate.
Discussion & Comments 0
Share your method, a shortcut, or ask about a step you didn't follow.
No comments yet. Be the first to share your solution!