C++ Programming - Functions - Discussion
Discussion Forum : Functions - Programs (Q.No. 31)
31.
Which of the following statement is correct about the program given below?
#include<iostream.h>
class IndiaBix
{
int x, y, z;
public:
IndiaBix(int x = 100, int y = 30, int z = 0)
{
this->x = x;
this->y = y;
this->z = z;
Display();
}
void Display()
{
cout<< x << " " << y << " " << z;
}
};
int main()
{
int a = 0, b = 1, c = 2;
int &x = ++a;
int &y = --b;
int z = c + b - -c;
IndiaBix objBix(x, y, z);
return 0;
}
Discussion:
4 comments Page 1 of 1.
Rupinder said:
1 decade ago
x has the value = ++a that is 0+1 = 1.
y has value --b ie 1-0 = 0.
Now z = c + b - -c = 2+0-(-2) = 2+2 = 4.
Now object is create and normal display function is called.
y has value --b ie 1-0 = 0.
Now z = c + b - -c = 2+0-(-2) = 2+2 = 4.
Now object is create and normal display function is called.
(2)
Anixx said:
4 years ago
Why 100, 30 & 0 not print? Please explain.
(1)
Ron said:
3 years ago
@Anixx.
Those are default arguments. If no arguments are passed then x, y, z will take 100, 30, and 0 respectively.
Those are default arguments. If no arguments are passed then x, y, z will take 100, 30, and 0 respectively.
Vanthana R said:
2 years ago
@All.
Because it executes the first main block of code so the output is 1 0 4.
Because it executes the first main block of code so the output is 1 0 4.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers