Can We Typecast Void into Int?

Can We Typecast Void into Int?

void pointer in C / C++
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. ... In C++, we must explicitly typecast return value of malloc to (int *).

Can we typecast void into int *?

You're return ing the value of int sum by setting a void * address to it. In this case, the address is not valid. But, if you keep that in mind and get the value of sum by casting a void * to int it will work.

How do I convert a void to int?

“convert void * to int” Code Answer's
  1. int a = 5;
  2. void *p = (void *)a;
  3. int b = (int)p;
Marcus Vance
Author

Marcus Vance

Marcus Vance is a cybersecurity auditor and technology writer dedicated to educating the public about online safety, data privacy regulations, enterprise security, and emerging cyber threats.