C++ Programming - References - Discussion
Discussion Forum : References - Programs (Q.No. 6)
6.
Which of the following statement is correct about the program given below?
#include<iostream.h>
int main()
{
int x = 10, y = 20;
int *ptr = &x;
int &ref = y;
*ptr++;
ref++;
cout<< x << " " << y;
return 0;
}
Discussion:
11 comments Page 2 of 2.
A student said:
7 years ago
Here *ptr holds the value of x means *ptr =10.
*Ptr++ =11.
But it doesn't change the value of x.
But &ref=y (is alias) means ref=y.
So ref++ means y++.
So the output is the value of x is 10.
And y is 21.
*Ptr++ =11.
But it doesn't change the value of x.
But &ref=y (is alias) means ref=y.
So ref++ means y++.
So the output is the value of x is 10.
And y is 21.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers