Since you tagged C++
in your question I will answer this on C++
For these type of conversions use static casting: static_cast
which can perform conversions between pointers to related classes, not only upcasts (from pointer-to-derived to pointer-to-base), but also downcasts (from pointer-to-base to pointer-to-derived). No checks are performed during runtime to guarantee that the object being converted is in fact a full object of the destination type. Therefore, it is up to the programmer to ensure that the conversion is safe
So back to your code:
#include<iostream>
using namespace std;
class car
{
public:
int i, j;
car() :i(5), j(9){};
car(int a, int b) :i(a), j(b){}
void display();
};
void car::display()
{
cout << i << j;
}
void main()
{
car *obj = new car;
void *p = obj;
//convert back to car from void.
car *casted_void_p = static_cast<car*>(p); //not safe - you may lose data or cause run time errors if casting from wrong object
casted_void_p->display();
}