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; 
}
The program will print the output 1 0 3.
The program will print the output 1 0 4.
The program will print the output 1 1 3.
The program will print the output 1 1 4.
The program will report compile time error.
Answer: Option
Explanation:
No answer description is available. Let's discuss.
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.
(2)

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.

Vanthana R said:   2 years ago
@All.

Because it executes the first main block of code so the output is 1 0 4.

Anixx said:   4 years ago
Why 100, 30 & 0 not print? Please explain.
(1)

Post your comments here:

Your comments will be displayed after verification.