Skip to content
Related Articles

Related Articles

Improve Article
C++ | References | Question 6
  • Difficulty Level : Easy
  • Last Updated : 06 Jan, 2014

Output of following C++ program?




#include<iostream>
using namespace std;
  
int main()
{
  int x = 10;
  int& ref = x;
  ref = 20;
  cout << "x = " << x << endl ;
  x = 30;
  cout << "ref = " << ref << endl;
  return 0;
}

(A)

x = 20
ref = 30

(B)

x = 20
ref = 20

(C)

x = 10
ref = 30

(D)

x = 30
ref = 30


Answer: (A)

Explanation: ref is an alias of x, so if we change either of them, we can see the change in other as well.

Quiz of this Question

Want to learn from the best curated videos and practice problems, check out the C Foundation Course for Basic to Advanced C.
My Personal Notes arrow_drop_up
Recommended Articles
Page :