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;
}
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.
$./testRef.
11 11.
Amoli said:
7 years ago
It is right to left evaluation.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers