Void pointer

In c++, we can’t assign the address of a variable of one data type to a pointer of another data type.

In such a case, use a void pointer or generic pointer.

Facts:

  1. malloc() and calloc() returns void * type and allow this function to be used to allocate memory of any data type.
  2. void pointers are used to implement a generic function in c.
  3. void pointer can’t be dereferenced.

Output:

4. void pointer doesn’t allow pointer arithmetic.

Program:

Output

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store