What is void pointer in C

1 Answer

0 votes
// A void pointer is a pointer that has no associated data type. 
// A void pointer can hold address of any type.

#include <stdio.h>

int main(void)
{
    int n = 12;
 
    void *p = &n;  
    printf("*p = %d\n", *(int *)p);
    
    char ch = 'a';

    p = &ch; 
    printf("*p = %c\n", *(char *)p);

    
    return 0;
}

  
/*
run:
  
*p = 12
*p = a

*/

 



answered Jun 21, 2017 by avibootz

Related questions

1 answer 167 views
167 views asked May 5, 2017 by avibootz
2 answers 125 views
125 views asked May 12, 2023 by avibootz
1 answer 132 views
1 answer 262 views
262 views asked Jun 20, 2017 by avibootz
2 answers 242 views
...