C++ Programming - References - Discussion

Discussion Forum : References - General Questions (Q.No. 12)
12.
Which of the following statements is correct?
  1. We can return a global variable by reference.
  2. We cannot return a local variable by reference.
Only 1 is correct.
Only 2 is correct.
Both 1 and 2 are correct.
Both 1 and 2 are incorrect.
Answer: Option
Explanation:
No answer description is available. Let's discuss.
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:

Your comments will be displayed after verification.