Page 14 - Sample_test_Float
P. 14

14  Functions and Pointers



               Example 2
               #include <stdio.h>
               struct book
               {
                  int pages;
                  float price;
               };
               void main()
               {
                  struct book *ptr;
                  struct book p;
                  ptr=&p;/* Referencing pointer to memory address of p */
                  printf(“Enter no of pages: “);
                  scanf(“%d”,&ptr->pages); // (*ptr).pages is equivalent to p.pages
                  printf(“Enter price: “);
                  scanf(“%f”,&ptr->price); // (*ptr).price is equivalent to p.price
                  printf(“/nDisplaying:/n “);
                  printf(“%d %f”,ptr->pages,*ptr->price);
               }

               Output:
               Enter no of pages:450
               Enter price: 220.75
               Displaying:
               450 220.75





              5.2.11. Void Pointer

              void pointer is a pointer that can store the address of any type of variable.

              Introduction
              •  Suppose if we have to declare integer pointer, character pointer and float pointer, then we need to declare
                 three pointer variables.
              •  Instead of declaring different types of pointer variable, it is possible to declare single pointer variable which
                 can act as integer pointer, character pointer or floating point pointer.
              This general purpose pointer variable is called void pointer.
              Advantages of void pointer:
              •  It does not have any data type associated with it.
              •  It can store address of any type of variable.

              Declaration of void pointer


               Syntax
               void * pointerVaraibleName;
   9   10   11   12   13   14   15   16   17