C++ Programming - Functions - Discussion
Discussion Forum : Functions - Programs (Q.No. 28)
28.
What will be the output of the following program?
#include<iostream.h>
class IndiaBix
{
int x, y, z;
public:
void Apply(int xx = 12, int yy = 21, int zz = 9)
{
x = xx;
y = yy += 10;
z = x -= 2;
}
void Display(void)
{
cout<< x << " " << y << endl;
}
void SetValue(int xx, int yy)
{
Apply(xx, 0, yy);
}
};
int main()
{
IndiaBix *pBix= new IndiaBix;
(*pBix).SetValue(12, 20);
pBix->Display();
delete pBix;
return 0;
}
Discussion:
5 comments Page 1 of 1.
Kobe said:
5 years ago
@Mayuresh.
Because when SetValue(12,22) is called, it calls Apply(12, 0, 22).
Then within Appy function.
The statement y = yy += 10;
It is evaluated as y = (0 + 10).
So y is 10.
Because when SetValue(12,22) is called, it calls Apply(12, 0, 22).
Then within Appy function.
The statement y = yy += 10;
It is evaluated as y = (0 + 10).
So y is 10.
Aparna said:
1 decade ago
Answer must be 10 10.
Because z = x- = 2.
Statement will also execute and it will decrement value of x by 2.
Because z = x- = 2.
Statement will also execute and it will decrement value of x by 2.
Kush said:
1 decade ago
z=x-=2.
This is same as z=(x=x-2).
Which changes the value of x, 12-2=10, x=10?
This is same as z=(x=x-2).
Which changes the value of x, 12-2=10, x=10?
Sapna said:
1 decade ago
Answer x=12, y=10.
Answer x=10, y=10 why?
Answer x=10, y=10 why?
Mayuresh Bhola said:
8 years ago
How come y is 10?
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers