C++ Structure and Function1 min read

The relation of structure and function in C++ is that just like any other argument passed in a function, a structure can also be passed.

Passing structure to function in C++

We can pass and access the structure to function as an argument in a program. It is similar to the way we pass a normal argument to a function. And it is also returned from a function just like any other argument.

Let us understand through an example.

Output:

Person Name: John Mathers
Person Roll: 32


Returning structure from function in C++

The output of this program is the same as the output of the above program.

In this program, the structure variable s stores the returned value from returnInfo() function where value is provided to structure members (s = returnInfo(s);).

After that, the s is passed to display() function where the information os student is displayed.


MORE

Keith Number Program in C

In this tutorial, we will write a Keith number in C. It is one of the most asked questions in an interview. Before that, you …
Read More

Keith Number Program in C++

In this tutorial, we will write a Keith number in C++. It is one of the most asked questions in an interview. Before that, you …
Read More

Singly linked list Program C++

In this tutorial, we will write a C++ program to implement singly linked list. In this program, we will create a separate function for each …
Read More

Fascinating Number Program in C

In this tutorial, we will write a C program to check whether the given number is a Fascinating number or not. You may go through …
Read More

Peterson Number in C

In this tutorial, we will learn about the Peterson number and check if the number is Peterson or not in C. What is Peterson Number? …
Read More

Peterson Number in C++

In this tutorial, we will learn about the Peterson number and write a C++ program to check if the given number is a Peterson number …
Read More