C++ Programming - References - Discussion
Discussion Forum : References - Programs (Q.No. 1)
1.
Which of the following statement is correct about the program given below?
#include<iostream.h>
int main()
{
int x = 80;
int y& = x;
x++;
cout << x << " " << --y;
return 0;
}
Discussion:
20 comments Page 2 of 2.
Vipul said:
8 years ago
cout << x << " " << --y.
This is processed right to left, starting with loading y, decrementing it and so on.
This is processed right to left, starting with loading y, decrementing it and so on.
Gabgame said:
1 decade ago
Actually position of '&' is incorrect. Otherwise using Visual studio 2010, it gives 80 80 output.
Atul Kumar said:
1 decade ago
Because the declaration of reference variable is wrong.
It should be as int &y = x;.
It should be as int &y = x;.
Sarvesh karan said:
7 years ago
Why it is compile time error. It should take as bitwise & and then proceed.
Pompy said:
1 decade ago
Answer is D as Y is storing the address of X, so --Y will result in error.
Sujeeth said:
1 decade ago
Declaration of y should be int& y = x; instead of int y& = x.
Vishal Gour said:
1 decade ago
Address is only stored by a pointer.
Kevin said:
10 years ago
Position of '&' is incorrect.
Vinay ramani said:
10 years ago
Declaration syntax error.
Sumi said:
1 decade ago
It should be y=&x;.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers