• admin@embedclogic.com

Structure Input In Function Call

Pass a structure as an argument in function

Write a Function to display employee detail through function “call by value” and “Call By reference”

Note: Here I am assuming that reader must have Idea of function calling method as I discussed in  “Call By Value and Call By Reference”

Call By structure Value

“Call By Structure Value” means pass the structure value as an Input to the function.

where emp is a structure.Lets understand through below example –

As You Can see :

display_Struct is a function with argument “emp” which is an structure variable itself.

display_Struct(emp); is calling it’s definition by passing value of the structure “emp” to print the information of emp on console.

empData is an local structure variable which take a copy of emp structure for further processing and will print by the use of dot(.) operator.

Call By structure Reference

“Call By Structure Reference” means pass the structure address as an Input to the function.

display_Struct(&emp); //Function Call by Reference

where emp is a structure.Lets understand through below example –

As You Can see :

display_Struct is a function with argument “emp” which is an structure variable itself.

display_Struct(&emp); is calling it’s definition by passing address of the structure “emp” to print the information of emp on console.

empData is an pointer variable of similar structure type which holds the address of emp structure and print all its information through -> operator.

Pass an Array of structure as an argument in function

In case of array I always recommend “Call by reference” method.You can follow below example to understand the concept.

Subscribe and stay updated with our latest articles.