Question 8
Back to Exercise
The program below does not compile. Which statement correctly describes the problem?
#include <iostream>
int main() {
double rate = 7.5;
int& r = rate;
std::cout << r << '\n';
return 0;
}
- A rate must be float
- B An int& cannot bind to a double; the types must match (const int& would bind to a converted temporary copy instead) Correct
- C References cannot hold decimals
- D r must be declared first
Correct Answer: Option B
const int& r = rate; compiles but refers to a temporary int with value 7, not to rate – often a surprise.
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!