C++ Programming - References - Discussion
Discussion Forum : References - Programs (Q.No. 23)
23.
Which of the following statement is correct about the program given below?
#include<iostream.h>
class IndiaBix
{
int a, b, c;
public:
void SetValue(int x, int y ,int z)
{
a = x;
b = y;
c = z;
}
void Display()
{
cout<< a << " " << b << " " << c;
}
};
int main()
{
IndiaBix objBix;
int x = 2;
int &y = x;
y = 5;
objBix.SetValue(x, ++y, x + y);
objBix.Display();
return 0;
}
Discussion:
8 comments Page 1 of 1.
Shivam said:
2 years ago
Why is the above code executed from right to left? Please explain to me.
Ilya said:
3 years ago
As per my knowledge, the Correct answer is 6 6 12.
(1)
Radu said:
9 years ago
Between the previous and next sequence point, the prior value of a scalar object that is modified by the evaluation of the expression, must be accessed only to determine the value to be stored. If it is accessed in any other way, the behavior is undefined.
Demented_hedgehog said:
10 years ago
From the C++ Standard, section 5.2.2/8: The order of evaluation of arguments is unspecified.
Don't check your compiler. You don't want to be writing code that works one way on one compiler and another way on a different compiler.
Don't check your compiler. You don't want to be writing code that works one way on one compiler and another way on a different compiler.
Kaka murli said:
10 years ago
First you check your compiler.
Aston Martin said:
1 decade ago
Correct answer is 5 6 12. Check on your compiler.
(1)
Atul said:
1 decade ago
objBix.SetValue(x, ++y, x + y);
The above executes from right to left.
So,
a) x+y=5+5=10.
b) ++y=6.
c) x=6 becz y is a reference of x.
Hence output is 6 6 10.
The above executes from right to left.
So,
a) x+y=5+5=10.
b) ++y=6.
c) x=6 becz y is a reference of x.
Hence output is 6 6 10.
(4)
Shivesh said:
1 decade ago
objBix.SetValue(x, ++y, x + y);
Value pass first from right;
Value pass first from right;
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers