#include <stdio.h>
int main(void) {
// Declare an integer and a void pointer to it
int num = 5;
void *ptr = #
// Print the value of the integer using the void pointer
printf("Value of num: %d\n", *(int*)ptr);
return 0;
}
This program declares an integer called num and a void pointer to it called ptr. It then prints the value of num using the void pointer ptr. To dereference a void pointer and access the value it points to, you need to cast it to the appropriate type using a type cast operator such as (int*).
Here is an example of the output of this program:
Value of num: 5

0 Comments