-->

Write a program to send an entire structure as a parameter to a function

Write a program to send an entire structure as a parameter to a function
Write a program to send an entire structure as a parameter to a function.
#include<stdio.h>
#include<conio.h>
struct stores
{
char name[20];
float price;
int quantity;
};
struct stores update(struct stores product, float p, int q); //function declaration
float mul(struct stores stock);
void main()  
{
float pincrement, value;
int qincrement;
struct stores item= { "xyz",25.75,12}; //Declaring and initializing 'item' of type 'stores'
printf("\n input increment values\n");
scanf(" %f %f", &pincrement, &qincrement);
item = update (item , pincrement, qincrement); //Calling the 'update' function
printf("updated values of item\n");
printf("name : %s\n", item.name);
printf("price :%f\n", item.price);
printf("quantity : %d\n", item.quantity);
value = mul(item) ; //Calling the 'mul' function
printf("\n value of the item = %f\n",value);
} //end main
struct stores update(struct stores product, float p) //function definition
{
product.price = product.price + p;
product.quantity = product.quantity + q;
return(product);
}
float mul(struct stores stack) //function definition
{
return(stock.price *stack.quantity);
}

OUTPUT:
input     increment values
10           20
updated values of item
name: xyz
price: 15.750000
quantity: 12
value of the item = 189.000000

Related Posts

Subscribe Our Newsletter