2. Definition
To represent a collection of data items of different
types using a single name.
general format of a structure
struct tag_name
{
data_type member1;
data_type member2;
.................
}
3. To declare a structure variable
The keyword struct.
The structure tag name.
List of variable names separated by commas.
A terminating semicolon.
For example :
struct book book1,book2;
To accessing a structure members using the dot
operator(.)
For example
book1.price
4. Arrays of structures
Declare an array of structures, each element of the array
representing a structure variable.
For example
struct class student[10];
Each element is defined to be the type struct class.
Consider the following declaration
struct class
{
int subject1;
int subject2;
};
5. Arrays within structures
Arrays as structure members.
We can use single-dimensional or multi-dimensional
arrays of type int or float.
For example
struct marks
{
int number;
float subject[3];
}student;
6. Structures and functions
Passing of structure values as arguments to
functions.
General definition
data_type function_name(struct str_name
str_var_name)
{
..............
return(expression);
}
Function calling
7. There are three methods by which the values of a
structure can be transferred from function
The first method is to pass each member of the
structure as an actual argument of the function call.
The second method involves passing of a copy of
the entire structure to the called function.
The third approach employs a concept called
pointers to pass the structure as an argument.