C – Structure and Function2 min read

Just like any other variables that are passed in a function, structure can also be pas structs to functions. But before that you must go through the following topics in C.


Passing structures to functions

While passing a structure we may pass the members of the structure or we can pass the structure variable itself. See the example below.

Output:

The variable of the structure (s1) itself is passed into the display_function function as an argument.


How to return a struct from a function

Go through the following example to see how a structure is returned from the function.

Output:

As you can see in the example, a separate structure variable (s) is declared inside the function (stud_detail()), and after entering all the information of the student, s is returned and displayed in the main function.


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