Example of Void Pointer in C++
The below example demonstrates the declaration and use of void pointer in C++.
C++
// C++ Program to demonstrate the declaration and use of a // void pointer #include <iostream> using namespace std; int main() { int a = 10; // void pointer holds address of int 'a' void * myptr = &a; // printing the value of a and adress of a stored in // myptr cout << "The value of a is: " << a << endl; cout << "The Adress of a is " << myptr << endl; } |
Output
The value of a is: 10 The Adress of a is 0x7ffd9ac02a64
void Pointer in C++
In C++, a void pointer is a pointer that is declared using the ‘void‘ keyword (void*). It is different from regular pointers it is used to point to data of no specified data type. It can point to any type of data so it is also called a “Generic Pointer“.