1.

What is a void pointer in C? Can a void pointer be dereferenced without being aware of its type?

Answer»

A VOID POINTER is a pointer that is useful in POINTING to the memory location having an undefined data type at the time of defining a variable, which means it can be any data of any arbitrary type. You can dereference a void pointer only after explicit casting. For example:

INT x = 10;void *y = &x;printf(“%d\n”, *((int*)y));

In the above-given CODE, we have declared a normal variable x with the integer data type, and assigned reference of x into a void pointer y. Using printf(), we are displaying the value of y by dereferencing it.



Discussion

No Comment Found