C++ Programming - References - Discussion

Discussion Forum : References - Programs (Q.No. 3)
3.
Which of the following statement is correct about the program given below?
#include<iostream.h> 
int main()
{
    int x = 10;
    int &y = x;
    x++;
    cout<< x << " " << y++;
    return 0; 
}
The program will print the output 11 12.
The program will print the output 11 11.
The program will print the output 12 13.
It will result in a compile time error.
Answer: Option
Explanation:
No answer description is available. Let's discuss.
Discussion:
14 comments Page 2 of 2.

Meenakshi L said:   9 years ago
Why we need to use & operator. What is the purpose to use that operator in above prog? Please, anyone clear my doubt.

Manickasundaram said:   8 years ago
This reference variable. Reference variable is used to refer predefined variable. Here X is predefined variable and why is reference variable. If we need to access predefined variable by using reference concept we must use & sign before of the reference variable.

Trudnai said:   8 years ago
I guess that is implementation dependent. I have just copy pasted the example and compiled by g++ and the result:

$./testRef.
11 11.

Amoli said:   7 years ago
It is right to left evaluation.


Post your comments here:

Your comments will be displayed after verification.