Explain with an example how one predefined data type can be converted to a user defined data type.
/*
*User defined types are usually objects made from use defined classes. Predefined types are data types
*Build in into the language and already have special meaning e.g int, float, doubl etc.
*In this example pointers have been used. The pointer is sued to reference the memory location
*of an integer type.
*/
#include <iostream>
using namespace std;
class MyClassType{
private:
int a;
public:
void display(){
cout<<"MyClassType a ="<< a << endl;
}
};
int main(){
int *ptr = new int();
*ptr = 10;
MyClassType *num = ((MyClassType *)ptr);
num->display();
return 0;
}
Comments
Leave a comment