C++ Programming - Functions - Discussion
Discussion Forum : Functions - Programs (Q.No. 37)
37.
What will be the output of the following program?
#include<iostream.h>
class BaseCounter
{
protected:
long int count;
public:
void CountIt(int x, int y = 10, int z = 20)
{
count = 0;
cout<< x << " " << y << " " << z << endl;
}
BaseCounter()
{
count = 0;
}
BaseCounter(int x)
{
count = x ;
}
};
class DerivedCounter: public BaseCounter
{
public:
DerivedCounter()
{ }
DerivedCounter(int x): BaseCounter(x)
{ }
};
int main()
{
DerivedCounter objDC(30);
objDC.CountIt(40, 50);
return 0;
}
Discussion:
2 comments Page 1 of 1.
MIDHUNGOPAL said:
8 years ago
Please explain it.
Prity Sinha said:
4 years ago
objDC.CountIt(40, 50);
It will intialize value of x and y in void CountIt(int x, int y = 10, int z = 20),
As rule says default value and override and default value order is right to left.
So x=40,y=50, z is consider as default which is 20.
It will intialize value of x and y in void CountIt(int x, int y = 10, int z = 20),
As rule says default value and override and default value order is right to left.
So x=40,y=50, z is consider as default which is 20.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers