Submitted Questions

  • A program in C using Void Pointer

    {geshibot language="c"}#include #include int main() { int a=10; void *p; p=&a; clrscr(); printf("%u",*p); getch(); return; }{/geshibot} I know that this program is wrong as error is shown on compiling it. Anyone please provide a simple program using Void pointer in C. Thanks in advance :)

    Ashok Kumar Orupalli

    • Sep 3rd, 2012

    You have to typecast void pointer to int as *(int*)p;

    Code
    1. #include<stdio.h>
    2. #include<conio.h>
    3. int main()
    4. {
    5.  int a=10;
    6.  void *p;
    7.  p=&a;
    8.  clrscr();
    9.  printf("%u",*(int*)p);
    10.  getch();
    11.  return 0;
    12. }

    Sereche

    • Jul 9th, 2012

    Your error is on line 9, where youve attempted to dereference a pointer to void (the expression *p). You can only dereference typed pointers. The solution you are probably looking for would be to repl...