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; 
}
99
ASCII value of 99
Garbage value
99.50
Answer: Option
Explanation:
No answer description is available. Let's 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; 
}
The program will print the output India.
The program will print the output Bix.
The program will print the output IndiaBix.
The program will report compile time error.
Answer: Option
Explanation:
No answer description is available. Let's 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; 
}
The program will print the output 25.
The program will print the output Garbage-value.
The program will report compile time error.
The program will report runtime error.
Answer: Option
Explanation:
No answer description is available. Let's 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; 
}
The program will print the output 5.
The program will print the output Garbage-value.
The program will report compile time error.
The program will report runtime error.
Answer: Option
Explanation:
No answer description is available. Let's 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;
}
1234
4321
12344321
12341234
43211234
Answer: Option
Explanation:
No answer description is available. Let's discuss.