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.
Aishwarya said:
4 years ago
Because the priority is to the increment:
*ptr++; // == *(ptr++);
So it's the value if the POINTER wich is incremented, not the value of 'x'.
But if you write this :
(*ptr)++; // The value of 'x'is incremented.
*ptr++; // == *(ptr++);
So it's the value if the POINTER wich is incremented, not the value of 'x'.
But if you write this :
(*ptr)++; // The value of 'x'is incremented.
(3)
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers