C++ | References | Question 5
#include<iostream> using namespace std; int &fun;() { int x = 10; return x; } int main() { fun() = 30; cout << fun(); return 0; } |
chevron_right
filter_none
(A) May cause runtime error
(B) May cause compiler error
(C) Always works fine.
(D) 0
Answer: (A)
Explanation: Since we return reference to a local variable, the memory location becomes invalid after function call is over. Hence it may result in segmentation fault runtime error.
Quiz of this Question
Recommended Posts:
- C++ | References | Question 6
- C++ | References | Question 1
- C++ | References | Question 4
- C++ | References | Question 6
- C++ | References | Question 6
- C++ | Constructors | Question 16
- C++ | Inheritance | Question 3
- C++ | Inheritance | Question 4
- C++ | Constructors | Question 17
- C++ | new and delete | Question 4
- C++ | new and delete | Question 1
- C++ | new and delete | Question 2
- C++ | new and delete | Question 3
- C++ | Constructors | Question 14
- C++ | Constructors | Question 15



