VOID POINTER - C-Tutorial

Latest

Monday, 3 October 2016

VOID POINTER

VOID POINTER


            A void pointer is a special type of pointer that can points to any data type variables.  The general format of a void pointer variable is:

                        Syntax                        :           void *ptrvariable;

                        Example         :           void *ptr;
                                                            int X;
                                                            float Y;
                                                            ptr = &X;
                                                            ptr = &Y;
           
For accessing value of the variable with the pointer variable, type casting must be placed to refer the specific data item.

/* EXAMPLE PROGRAM FOR VOID POINTER */
main()
{
            int x=10;
            double y=3.45678;
            void *ptr;
            clrscr();
            ptr=&x;
            printf("\nValue 1         =%d",*(int *)p);
            ptr=&y;
            printf("\nValue 2         =%lf",*(double *)p);

}

No comments:

Post a Comment