C++ Programming - Constructors and Destructors

Exercise :: Constructors and Destructors - Programs

1. 

What will be the output of the following program?

#include<iostream.h> 
class IndiaBix
{
    int x; 
    public:
    IndiaBix(int xx, float yy)
    {
        cout<< char(yy);
    } 
}; 
int main()
{
    IndiaBix *p = new IndiaBix(35, 99.50f);
    return 0; 
}

A. 99
B. ASCII value of 99
C. Garbage value
D. 99.50

Answer: Option B

Explanation:

No answer description available for this question. Let us discuss.

2. 

Which of the following statement is correct about the program given below?

#include<iostream.h> 
class IndiaBix
{
    public:
    IndiaBix()
    {
        cout<< "India";
    }
    ~IndiaBix()
    {
        cout<< "Bix";
    }
};
int main()
{
    IndiaBix objBix;
    return 0; 
}

A. The program will print the output India.
B. The program will print the output Bix.
C. The program will print the output IndiaBix.
D. The program will report compile time error.

Answer: Option C

Explanation:

No answer description available for this question. Let us discuss.

3. 

Which of the following statement is correct about the program given below?

#include<iostream.h> 
class Bix
{
      int x; 
    public:
      Bix();
     ~Bix();
      void Show() const;
};
Bix::Bix()
{
    x = 25;
}
void Bix::Show() const
{
    cout<< x;
}
int main()
{
    Bix objB;
    objB.Show();
    return 0; 
}

A. The program will print the output 25.
B. The program will print the output Garbage-value.
C. The program will report compile time error.
D. The program will report runtime error.

Answer: Option C

Explanation:

No answer description available for this question. Let us discuss.

4. 

Which of the following statement is correct about the program given below?

#include<iostream.h> 
class Bix
{
      int x; 
    public:
      Bix();
      void Show() const;
      ~Bix(){}
};
Bix::Bix()
{
    x = 5;
}
void Bix::Show() const
{
    cout<< x;
}
int main()
{
    Bix objB;
    objB.Show();
    return 0; 
}

A. The program will print the output 5.
B. The program will print the output Garbage-value.
C. The program will report compile time error.
D. The program will report runtime error.

Answer: Option A

Explanation:

No answer description available for this question. Let us discuss.

5. 

What will be the output of the following program?

#include<iostream.h> 
int val = 0; 
class IndiaBix
{
    public: 
    IndiaBix()
    {
        cout<< ++val;
    }
    ~IndiaBix()
    {
        cout<< val--; 
    } 
}; 
int main()
{
    IndiaBix objBix1, objBix2, objBix3;
    {
        IndiaBix objBix4;
    } 
    return 0;
}

A. 1234
B. 4321
C. 12344321
D. 12341234
E. 43211234

Answer: Option C

Explanation:

No answer description available for this question. Let us discuss.