Doubt in (void *) for type conversion!

Hi Coding Blocks TA,

I am not able to understand why (void *) is used for type conversion.

Can’t we use simply (void) for type conversion?

Also in the video Prateek bhaiya said that we can use (int) also for typecasting, but it’s giving error!!

Can you please help me in finding the correct solution with detailed explanation?

Thank you & have a nice day!!:blush:

Hey @Shivam01 A void pointer is a pointer that has no associated data type with it. A void pointer can hold address of any type and can be typcasted to any type.

char x =‘A’;
void *temp=&x;
cout<< (void *)&x <<" "<<temp<<endl;
both will give same result
i.e saving address of x in temp pointer and then printing pointer .

For that you have to share your code with me, so that i can tell you where ar you doing it wrong.
If you have any other doubts left, feel free to ask.

its giving error for (int) but working for (int *). can you explain this??

This is for pointer variable

This is explicitly converting any other data type to int. Rest to give you a precise info, share your code with me.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.