🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← 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;
}
  1. A.5 6
  2. B.6 6
  3. C.6 7
  4. 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 →