392 Programming and Data Structures
Explanation In the above example structure name has member variables like a character a r r a y
name [2 5 ], age and w eight of integer type. We have passed the base address of name but values
of age and wt. Thus, here values are passed using call by reference and call by value methods.
Instead of passing each element also one can pass entire structure into the function. This is shown in
the given program below.
12.15 Write a program to pass entire structure to user defined function.
I* passing entire structure to function */
# inclu de < s td io .h >
# inclu d e <conio.h>
st r u c t boy
{
char name[2 5 ];
in t age;
in t w t;
v o id m ain()
struct boy bla{*Amit', ,20,25};
print ( b l ) ;
}
p rin t (s tru c t boy b)
{
clrscr();
printf ("tt %s % d %d",b.name,b.age,b.ivt);
return 0;
I
QUJFUT
Amit 20 25
Explanation In the above program s tru c tu re boy is defined outside the main ( ) . So it is
global and every function can access it. The object defined on stru c tu re boy b l is passed to
function prin t ( ) . The formal argument (object) of function p rin t ( ) receives contents of object bl.
Thus, using dot operator contents of individual elements are displayed.