top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

What is a void pointer?

0 votes
134 views
What is a void pointer?
posted Jul 22, 2014 by anonymous

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

0 votes

Void pointer is a special type of pointer that can point to any data type. A void pointer is declared like a normal pointer, using the void keyword as the pointer’s type.

Example
int a = 5;
void *pVoid = &a; // pVoid is now pointing to an integer

Few things to remember -
1. A void pointer can not be dereferenced, a void pointer must first be explicitly cast to another pointer type before it is dereferenced.
2. It is not possible to do pointer arithmetic on a void pointer.

As a good programming practice avoid void pointer as much as possible.

answer Jul 22, 2014 by Salil Agrawal
Similar Questions
+2 votes

If I correct , by default main () function has integer return type.
I want to know what happens in the system internally when its return type gets changed from integer to void ?

+2 votes

Many a times in C we get these two type of main function one had void as parameter one has none. Now the question is what is the difference between these two?

...