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 1 of 2.
Anusha said:
5 years ago
The output is 11 11.
(4)
Swetha said:
6 years ago
The output is :11 11.
(4)
Amoli said:
7 years ago
It is right to left evaluation.
Hatos said:
8 years ago
I got this output as 11 11.
Am I right?
Am I right?
(2)
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.
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.
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.
Purvi said:
9 years ago
@Vijay.
The output of first is 11 10.
The second is 10 10.
So, what everyone is saying is correct.
The output of first is 11 10.
The second is 10 10.
So, what everyone is saying is correct.
Vijay said:
9 years ago
Try this too.
int x = 10;
int &y = x;
cout<< y++ << " " <<y;
int x = 10;
int &y = x;
cout<< y++ << " " <<y;
Vijay said:
9 years ago
If you say cout executes from right to left then try this.
int y = 10;
cout<<y<< " " <<y++;
int y = 10;
cout<<y<< " " <<y++;
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers