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;
}
Discussion:
14 comments Page 1 of 2.
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.
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.
Raju said:
1 decade ago
Why this happens? Why it does not treat it short or float?
Swapnil said:
9 years ago
I agree with you @Raju.
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.
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.
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.
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.
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)
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().
Even in GCC if you just write main() it is treated as int main().
Gayana said:
7 years ago
I agree with you @Raju.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers