From 482130578c6b4ddaf8606b334056b5436bc2d3ea Mon Sep 17 00:00:00 2001 From: Tejaswini Khandekar <90246533+teekhandekar@users.noreply.github.com> Date: Mon, 15 Nov 2021 22:35:19 +0530 Subject: [PATCH] Create passing structure in function --- DAY51/passing structure in function | 41 +++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 DAY51/passing structure in function diff --git a/DAY51/passing structure in function b/DAY51/passing structure in function new file mode 100644 index 0000000..498994c --- /dev/null +++ b/DAY51/passing structure in function @@ -0,0 +1,41 @@ +#include + +//Lets create a structure first +struct FirstStruct +{ + int Num1; + int Num2; +}FirstStruct_IP; + +//function declarations +struct FirstStruct TakeUserInput(void); +void DisplayOutput(struct FirstStruct Input); + +//structure object declaration +struct FirstStruct inputStruct; + +int main() +{ + //create a structure to get a return from TakeUserInput function + //Now use the DisplayOutput to print the input + DisplayOutput(TakeUserInput()); + + return 0; +} + +//This function returns a structure after storing the user input into it +struct FirstStruct TakeUserInput(void) +{ + + printf("Enter a number: "); + scanf("%d",&inputStruct.Num1); + printf("Enter a number again: "); + scanf("%d",&inputStruct.Num2); + + return inputStruct; +} +//Function taking Structure as argument +void DisplayOutput(struct FirstStruct Input) +{ + printf("%d\n",((Input.Num1)+(Input.Num2))); +}