Logo 
Search:

C Programming Articles

Submit Article
Home » Articles » C Programming » Homework HelpRSS Feeds

Use of structure pointers as function parameters

Posted By: Alexander Evans     Category: C Programming     Views: 2648

Use of structure pointers as function parameters

Code for Use of structure pointers as function parameters in C Programming

struct stores                                                    
   {                                                                
        char  name[20];                                             
        float price;                                                
        int   quantity;                                             
   };                                                               
   main()                                                           
   {                                                                
        void update(struct stores *, float, int);                                              
        float         p_increment, value;                    
        int           q_increment;                                  
                                                                    
        struct stores item = {"XYZ", 25.75, 12};             
        struct stores *ptr = &item;                                 
                                                                    
        printf("\nInput increment values:");                        
        printf(" price increment and quantity increment\n");        
        scanf("%f %d", &p_increment, &q_increment);                 
                                                                    
   /* - - - - - - - - - - - - - - - - - - - - - - - - - - - */
update(&item, p_increment, q_increment); /* - - - - - - - - - - - - - - - - - - - - - - - - - - - */
printf("Updated values of item\n\n"); printf("Name : %s\n",ptr->name); printf("Price : %f\n",ptr->price); printf("Quantity : %d\n",ptr->quantity); /* - - - - - - - - - - - - - - - - - - - - - - - - - - - */
value = mul(&item); /* - - - - - - - - - - - - - - - - - - - - - - - - - - - */
printf("\nValue of the item = %f\n", value); } void update(struct stores *product, float p, int q) { product->price += p; product->quantity += q; } float mul(struct stores *stock) { return(stock->price * stock->quantity); } Output Input increment values: price increment and quantity increment 10 12 Updated values of item Name : XYZ Price : 35.750000 Quantity : 24 Value of the item = 858.000000
  
Share: 


Didn't find what you were looking for? Find more on Use of structure pointers as function parameters Or get search suggestion and latest updates.

Alexander Evans
Alexander Evans author of Use of structure pointers as function parameters is from London, United Kingdom.
 
View All Articles

 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
No Comment Found, Be the First to post comment!