Structures and arrays

:: Big Index :: C/C++ Programming Tutorials ::

Requirements

Basic programming knowledge

Understanding of structue

Compiler to compile and run code

Structure and array can be implemented together. An array is a group of identical data items. All array elements are sorted consecutive memory location under a common variable name. For structure, this type of common variable name is referred as arrays of structures and can be implemented similar to array.

For example, employee information can be implemented by the following array of structure:

struct company{
long int employee_id;
char sex;
int age ;
};

company employee[100];

In the above code segment, employee[100] is a structure variable which can store 100 employee information. Each elements are referred by the index. So, it can be accessed like the array. For each employee, it contains three type of information i.e. employee_id, sex and age.

Initializations of arrays of structures

Arrays of structures can be initialized statically or externally from the user.

Static initialization : Case 1

For static initialization, all values are initialized. So, the compile set values for each of the members. For example,

Here arrays are used. For each "employee[i]" array it takes the value from the user by the "object[index].variable". Thus "employee[i].emplyee_id", "employee[i].sex" and "employee[i].age" collects values from the user. Here "i" means the index.

Finally, the "display(...)" function will display the entered information.

More about "Structures"

Structures and arraysProgramming Tutorials : C/C++ Programming Structure and array can be implemented together. An array is a group of identical data items. All array elements are sorted consecutive memory location under a...

Structues and FunctionsProgramming Tutorials : C/C++ Programming Function decomposes any complex program into several manageable modules. Each module is referred as function. Functions are compiled separately. So, they can be...

Nested Structures : Structures within StructuresProgramming Tutorials : C/C++ Programming Structures can be implemented with functions and arrays. Moreover, structures can be implemented as the member of other structure. This is termed as structure within...