Write a C program to demonstrate example of structure pointer


Introduction

I have used Code::blocks 12 compiler for debugging purpose. But you can use any C programming language compiler as per your availability.


techstudy.org

HP 15 Core i3 7th gen Laptop(4GB, 1TB HDD, Windows 10) | Rs. 31,490

Write a C program to demonstrate example of structure pointer


  1. #include <stdio.h>
  2.  
  3. struct item
  4. {
  5. char itemName[30];
  6. int qty;
  7. float price;
  8. float amount;
  9. };
  10.  
  11. int main()
  12. {
  13.  
  14. struct item itm;
  15. struct item *pItem;
  16.  
  17. pItem = &itm;
  18.  
  19. // reading values using pointer
  20. printf("Enter product name: ");
  21. gets(pItem->itemName);
  22. printf("Enter price:");
  23. scanf("%f",&pItem->price);
  24. printf("Enter quantity: ");
  25. scanf("%d",&pItem->qty);
  26.  
  27. //calculating total amount of all quantity
  28. pItem->amount =(float)pItem->qty * pItem->price;
  29.  
  30. //printing item details
  31. printf("\nProduct Name: %s",pItem->itemName);
  32. printf("\nProduct Price: %f",pItem->price);
  33. printf("\nProduct Quantity: %d",pItem->qty);
  34. printf("\nTotal Amount: %f",pItem->amount);
  35.  
  36. return 0;
  37. }
  38.  

Result

C language techstudy.org

     





Related Topics




Popular Posts