← Quiz: References and Functions: all 10 questions
Quiz: References and Functions · Question 8 of 10
What does this print? (code)
What does this print?
#include <iostream>
using namespace std;
int main() {
int x = 5;
int &r = x;
r++;
int y = r;
y++;
cout << x << " " << y << "\n";
return 0;
}
- A.5 6
- B.6 6
- C.6 7
- D.7 7
Answer & explanation
Correct answer: 6 7
r is another name for x, so r++ makes x 6. y is a separate copy, so y++ changes only y.
Can you get the rest right without peeking?
Take the timed Quiz: References and Functions quiz free. Pass it to earn XP and count towards your certificate.
Start the quiz →