C++ Programming - References - Discussion
Discussion Forum : References - General Questions (Q.No. 12)
12.
Which of the following statements is correct?
- We can return a global variable by reference.
- We cannot return a local variable by reference.
Discussion:
23 comments Page 3 of 3.
Preetham said:
1 decade ago
You cannot return reference of local variable, by return statement function ends and memory attached to the local variable will be deleted or freed by the compiler. So the reference does not have anything to refer local variable is already deleted.
Vinay said:
1 decade ago
We can return the global variable by reference and it is wrongly answered here. The correct option is C.
Rahul said:
1 decade ago
@nidhi : Agreed !!! both options are correct..
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers