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;
}
The program will print the output 80 80.
The program will print the output 81 80.
The program will print the output 81 81.
It will result in a compile time error.
Answer: Option
Explanation:
No answer description is available. Let's discuss.
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.

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;.

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:

Your comments will be displayed after verification.