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.
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.
No delete has been called and the pointer is not a smart pointer.
(1)
Raj said:
5 years ago
Why final not printed? Please explain about it.
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.
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)
Saman said:
7 years ago
There should be a statement for namespace (using namespace std), otherwise it cause an error.
Gayana said:
7 years ago
I agree with you @Raju.
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().
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)
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.
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.
Swapnil said:
9 years ago
I agree with you @Raju.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers