🎙 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 1 of 10

What does this print? (code)

What does this print?

#include <iostream>
using namespace std;
void f(int &x) { x = x * 2; }
int main() {
    int a = 7;
    f(a);
    cout << a;
    return 0;
}
  1. A.7
  2. B.14
  3. C.0
  4. D.Error
Answer & explanation

Correct answer: 14

x is a reference to a, so a becomes 14.

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 →