Showing posts with label Structures in Funcions. Show all posts
Showing posts with label Structures in Funcions. Show all posts

Jun 21, 2020

Structures in Functions in C++ | Passing and returning Structure in functions | Coding Winds | We care about the future of future

 Structures and Functions

If you have gone through our Structure in C++ article, then there must be a doubt in your mind, about the combination of structures and functions. 

Passing Structure as an argument

Hello people in this blog we are going to read about the various ways we can pass Structure as an argument in a function. We can pass structure in function as any other argument.

For passing an array as an argument look at the example given below :

Here the output will be :

So yes this is how we can pass a structure as an argument in a function, now we will see how to return structure from a function.

Returning a Structure from a Function

For returning a structure from a function, we can look for the below given example :

The input and output here will be :

INPUT :

OUTPUT :

Here you can see that Structure S2 is wholly copied to S1 by just using ‘=’ operator.

Hence, value of all members of structure variable can be assigned to another structure using ‘=’ operator if both structures are of same type then we don’t need to manually assign the values.

We want to acknowledge, book "Computer Fundamentals and Programming in C" by Pradip Dey, this book helped us alot during our research for this article, also this is the best one for understanding the concepts of C programming, we personally recommend you to go for this, check it out by clicking here.

Hope all your doubts regarding this are clear now.

If you still have any doubt on this topic then do come to us via email "sophomoretechs@gmail.com" or via instagram "@coding.winds".