Showing posts with label structure. Show all posts
Showing posts with label structure. Show all posts

Saturday, May 10, 2008

Structure(Giving values to member )

Giving values to member

The link between a member and a variable is established
using member operator `.' to dot operator.

An example program to define a structure and assign
value to members:



Out put of the program

Structure( Passing structure to function )

Passing structure to function



There are three methods by which the values of structure can be transferred
from one function to another:

1. The first method is to pass each member of the structure
as an actual argument of the function call.

The actual argument is then treated independently like ordinary variables.

2. The second methods involve passing of a copy of the
entire structure to the called function

Since the function is working on a copy of the entire
structure to the called function, changes are not reflected in the original structure (in the calling function).

It is necessary for the entire function to return the
entire structure back to the calling function.

3. The third approach employs a concept called pointers
to pass the structure as an argument
.

In this case, the address location of the structure is
passed to the called function.

The function can access indirectly the entire structure
and work on it.

The general format of sending a copy of structure to the
called function is:

function_name (structure_variable_name)

Copyright

Copyright © 2008 C Tutorial, All rights are reserved