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; 
}
The program will print the output 10 20.
The program will print the output 10 21.
The program will print the output 11 20.
The program will print the output 11 21.
It will result in a compile time error.
Answer: Option
Explanation:
No answer description is available. Let's discuss.
Discussion:
11 comments Page 2 of 2.

Ghanshyam said:   1 decade ago
*ptr++;
this statement will not increase value of x by 1
* and ++ have same precedence..
associativity of both of them is from right to left.
first ++ evaluated then * , so it doesn't increase value, instead after execution of this statement ptr will point to next location..
(1)


Post your comments here:

Your comments will be displayed after verification.