C - Language Theory
Structures
1. A structure is a collection of variable of different data types under a single name.
2. The variables are called members of the structure.
3. The structure is also called a user-defined data type.
You can see how to
- The structure is something similar to an array; the only difference is array is used to store the same data types.
- The keyword 'struct' is used to declare the structure in C
- Variables inside the structure are called members of the structure.
(You can perform such operations using the pre-defined functions of “string.h” header file. In order to use these string functions you must include string.h file in your C program)
You can use the gets() function to read the line of string and can also use puts() to display the string.
Structure Declaration
//member variable 1
//member variable 2
//member variable 3
}[structure_variable];
char name[40];
int id[10];
float salary[50];
}[structure_variable];
Note: In above declaration 'employe' is name of the structure. And name, salary and id are members of the structure in this case.
Declaration of Structure Variables
struct employee { char name[40]; int id[10]; float salary[50]; } main () { struct employee2 } or struct employee { char name[40]; int id[10]; float salary[50]; } el,e2; |