12.6 POINTER TO VOID

C++ allows us to declare a pointer-to void. Consider the following declaration:

void * ptr1;

It declares a variable ptr1 of type pointer. It points to void. You may wonder what the use of such pointer declaration is. We have studied some functions, which are of type void. Even if they do not return any value, they do some processing/computing and the effect felt outside the function body through reference parameters. There can be no variables or objects that can be declared as void. Then what is the significance of this declaration?

It may be noted that a pointer can point to an integer or a double or even an object. Such pointers are grammatically different from each other. However, internal representation of a pointer is ...

Get Object Oriented Programming with C++, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.