C++ | References | Question 6
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; } |
chevron_right
filter_none
(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
Recommended Posts:
- C++ | References | Question 1
- C++ | References | Question 6
- C++ | References | Question 5
- C++ | References | Question 6
- C++ | References | Question 4
- References in C++
- Pointers vs References in C++
- Can references refer to invalid location in C++?
- Default Assignment Operator and References
- C | Operators | Question 27
- C | Operators | Question 8
- C | Operators | Question 7
- C | Operators | Question 6
- C | Operators | Question 5
- C | Arrays | Question 2



