Professional Documents
Culture Documents
MODULE 3
• C allows programmers to pass a single or entire structure information to or from a
function.
variable may be passed as a value or reference. The function will return the value
The structure addition have three variables( a, b, c) which are also known as
structure members. The variables are reads through scanf function. The next
statement illustrates that the structure members can be passed to the function
add. The add function defined to perform addition operation between two
values.
#include <stdio.h>
Passing The Entire Structure To Functions
//structures declaration
//Function Definition
typedef struct {
void add(sum s)
int a, b;
{
int c;
int sum1;
}sum;
sum1 = s.a + s.b;
void add(sum) ; //function declaration with struct type sum
printf("\nThe sum of two values are :%d ", sum1);
int main()
}
{
sum s1;
printf("Enter the value of a : ");
scanf("%d",&s1.a);
printf("\nEnter the value of b : ");
scanf("%d",&s1.b);
Output
add(s1); //passing entire structure as an argument to
function
Enter the value of a 10
return 0;
Enter the value of b 20
}
The sum of two values 30