C++ Programming - Constructors and Destructors - Discussion

Discussion Forum : Constructors and Destructors - Programs (Q.No. 12)
12.
Which of the following statement is correct about the program given below?
#include<iostream.h> 
class IndiaBix
{
    int x; 
    public:
    IndiaBix(short ss)
    {
        cout<< "Short" << endl;
    }
    IndiaBix(int xx)
    {
        cout<< "Int" << endl;
    }
    IndiaBix(float ff)
    {
        cout<< "Float" << endl;
    }
    ~IndiaBix() 
    {
        cout<< "Final";
    }
};
int main()
{
    IndiaBix *ptr = new IndiaBix('B');
    return 0; 
}
The program will print the output Short .
The program will print the output Int .
The program will print the output Float .
The program will print the output Final .
None of the above
Answer: Option
Explanation:
No answer description is available. Let's discuss.
Discussion:
14 comments Page 1 of 2.

VIVEK ROY said:   5 years ago
Please see the steps:

1. At first. the compiler will try for an exact match.
2. If failed, then it will do integral promotion, (char->int, float->double) and try to match, what it's doing here.
3. If failed. then it will do for built-in conversion and try to match.
4. If failed, then it will try user-defined conversion and match again.
(3)

Harsh said:   7 years ago
1. char B means we have defined a variable which is of type char and will store characters such a,b,X etc.

2, int x='B' means as follows:
(a)Any character that is represented under quotes (' ') will be treated as ASCII numbers which can be stored in any variable of type int.
(b)Here,int x ='B' is equivalent to int x = 66.
(1)

Shatya kesarwani said:   8 years ago
This program have no char type argument fun so compiler change the 'B' as ASCII code and passed to the INT type argument, but if we have char type argument fun then that time char argument type fun called.

Mohan Rana said:   8 years ago
I agree with @Arvind.

Because in case of implicit type conversion when such condition arise then datatype always convert to next nearest and higher data type. In given question it's INT.

Arvind said:   1 decade ago
There is no overloaded constructor for char, so compiler will treat 'B' as 66 (ASCII value of B) due to implicit type conversion from char to int.

Altu said:   5 years ago
Final is not printed because Object is not deleted.
No delete has been called and the pointer is not a smart pointer.
(1)

Sarvesh karan said:   7 years ago
Int is default return type in c++.

Even in GCC if you just write main() it is treated as int main().

Saman said:   7 years ago
There should be a statement for namespace (using namespace std), otherwise it cause an error.

Raju said:   1 decade ago
Why not constructor with 'short' argument was selected. Could somebody please explain?

Raju said:   1 decade ago
Here pass in char B but char argument is not passed their so by print INT.


Post your comments here:

Your comments will be displayed after verification.