C++ Programming - Functions - Discussion
Discussion Forum : Functions - Programs (Q.No. 41)
41.
Which of the following statement is correct about the program given below?
#include<iostream.h>
static int Result;
class India
{
public:
void Change(int x = 10, int y = 20, int z = 30)
{
cout<< x + y + z;
}
void Display(int x = 40, float y = 50.00)
{
Result = x % x;
cout<< Result;
}
};
class Bix
{
int x, y;
public:
void Change(int x, int y = 50)
{
cout<< x + y;
}
};
class IndiaBix: public India, public Bix
{
public:
void Display(int x = 10, int xx = 100, int xxx = 1000)
{
Result = x + xx % x * x;
cout<< Result ;
}
};
int main()
{
IndiaBix objBix;
objBix.India::Display(10, 20.00);
return 0;
}
Discussion:
4 comments Page 1 of 1.
Mallanagouda said:
3 years ago
@All.
The answer will be zero because you are taking a modulus of x%x.
So, definitely, 10%10 will be zero there is no other number.
The answer will be zero because you are taking a modulus of x%x.
So, definitely, 10%10 will be zero there is no other number.
Deepak said:
7 years ago
The answer is 0. Because in the main method it calls the base class display method.
(objBix.India::Display )-> by this we can actually call the overridden method by base class.so it invokes the base class method display so answer is zero.
(objBix.India::Display )-> by this we can actually call the overridden method by base class.so it invokes the base class method display so answer is zero.
Neha said:
1 decade ago
No answer is 0. Because one of the operand is integer there so float gets converted to int implicitly and mod operation takes place.
Dipak said:
1 decade ago
I think answer will be error because we can't use % with float value.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers