Passing Structure to function in C language

Passing Structure to function in C language

In this article, we will discuss the concept of “passing structure” to function in C language.

A structure can be passed to any function from main or sub functions as an argument.

There are two way to pass stucture as function argument

  • passing to a function by value
  • passing to a function by reference(address)

Passing structure by value

In this case, the structure variable can be passed as argument as a normal variable(by value) to the definition of function. A “structure” represents the members of structure with their values. This structure can be accessed from called function.

Structure to function Example

Output

student id is :3
student Name is :saru
student Average is :74.599998

Passing structure by reference

In this case, the structure variable can be passed as  argument as a pointer variable (passed by refferance) to the definition of function. A structure  represents the members of structure with their values. This structure can be accessed from called function by its address(using pointer variable).

Structure to function – example

Output

student id is :13
student Name is :Jhon
student Average is :59.700001

Related post

Structure in C Language                                       Structure in C++ Language
Function in C Language                                           Nested structure  in C access with variable
Nested function  in C                                              Nested structure in C++


Structure with function in C Language

Karmehavannan

Recent Posts

Multiply two numbers in Java using scanner| 5 different ways

Multiply two numbers in Java using scanner| 5 different ways In this article, we will…

9 months ago

5 different ways to Divide two numbers in Java using scanner

5 Different ways to Divide two numbers in Java using scanner In this article, we…

10 months ago

Learn 8 Ways to Subtract Two Numbers Using Methods in Java

Learn 8 Ways to Subtract Two Numbers Using Methods in Java In this article, we…

10 months ago

10 ways to subtract two numbers in Java

10 ways to subtract two numbers in Java In this article, we will discuss the…

10 months ago

Java Code Examples – Multiply Two Numbers in 5 Easy Ways

Java Code Examples – Multiply Two Numbers in 5 Easy Ways In this article, we…

10 months ago

How to Divide two numbers in Java| 5 different ways

How to Divide two numbers in Java| 5 different ways In this article, we will…

10 months ago

This website uses cookies.