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

String Pattern Programs in C

In this tutorial, we will write various C pattern programs for String. Before that, you may go through the following topics in C. for loop …
Read More

Java Program to Find pair of Integers in Array whose sum is given Number

In this tutorial, we will write a program to find a pair of elements from an array whose sum equals a given number in java …
Read More

Program to Print Diamond Alphabet Patterns in C

In this tutorial, we will learn to write a C program to print Diamond patterns using alphabets/characters. However, in this tutorial, we will create a …
Read More

Half Diamond Pattern in C using Alphabets

In this tutorial, we will learn and code the half diamond alphabet patterns in C programming language. However, in this tutorial, we will create a …
Read More

Half Pyramid of Alphabets in C

In this tutorial, we will learn and code alphabet patterns in C programming language specifically the Half pyramid of alphabets in C programming. However, in …
Read More

Inverted Half Pyramid Pattern of Alphabets in C

In this tutorial, we will write a C program to print half Pyramid using alphabets/characters. Before that, you may go through the following topic in …
Read More