Answer to Question #180971 in C++ for Kiran

Question #180971

Explain with an example how one predefined data type can be converted to a user defined data type.


1
Expert's answer
2021-04-13T07:32:55-0400
/*
*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;
    }

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS