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

Subtract two numbers using method overriding

Subtract two numbers using method overriding   Program 1

3 months ago

PHP Star triangle Pattern program

PHP Star triangle Pattern program Here's a simple Java program that demonstrates how to print…

3 months ago

Using function or method to Write temperature conversion : Fahrenheit into Celsius

Using Function or Method to Write to temperature conversion: Fahrenheit into Celsius In this article,…

1 year ago

Function or method:temperature conversion from Fahrenheit into Celsius – Entered by user

Function or method of temperature conversion from Fahrenheit into Celsius In this article, we will…

1 year ago

Write temperature conversion program: Fahrenheit into Celsius

Write temperature conversion program: from Fahrenheit to Celsius In this article, we will discuss the…

1 year ago

How to write a program to convert Fahrenheit into Celsius

How to write a program to convert Fahrenheit into Celsius In this article, we will…

1 year ago

This website uses cookies.