C Programming
Computer Programming

C program to demonstrate example of structure pointer



Write a C program to demonstrate example of structure pointer

\* C program to demonstrate example of structure pointer *\

# include < stdio.h >
# include < conio.h >
struct   item
{

char itemName[30] ;
int qty ;
float price ;
float amount ;

} ;

int   main( )
{

struct item itm ;
struct item *pItem ;
pItem = &itm ;

/* read values using pointer */
printf("\n Enter product name: ") ;
gets(pItem->itemName ) ;
printf(" Enter price:" ) ;
scanf("%f",&pItem->price ) ;
printf(" Enter quantity: " ) ;
scanf("%d",&pItem->qty ) ;

/* calculate total amount of all quantity */
pItem->amount =(float)pItem->qty * pItem->price ;

/* print item details */
printf("\n Name: %s",pItem->itemName ) ;
printf("\n Price: %f",pItem->price ) ;
printf("\n Quantity: %d",pItem->qty ) ;
printf("\n Total Amount: %f",pItem->amount ) ;
return 0 ;

}

Output of Program :

Output of C program to demonstrate example of structure pointer