
210 Data Structures Using C
/* Print data through arrow operator */
printf (“\n The data for the item...”);
printf (“\nCode : %s”, ptr −> code);
printf (“\nQty : %d”, ptr −> Qty);
printf (“\nCost : %5.2f”, ptr −> cost);
}
From the above program, we can see that the members of a static structure can be accessed by both
dot and arrow operators. However, dot operator is used for simple variable whereas the arrow operator
is used for pointer variables.
Example 5: What is the output of the following program?
#include <stdio.h>
main()
{
struct point
{
int x, y;
} polygon[]= {{1,2},{1,4},{2,4},{2,2}};
struct point *ptr;