Professional Documents
Culture Documents
Structure: Lesson 4
Structure: Lesson 4
Lesson 4
Structure
• A structure is a composite data type that defines a grouped list of variables that are to
be placed under one name in a block of memory.
• It allows different variables to be accessed by using a single pointer to the structure.
• a composite data type (or record) declaration that defines a physically grouped list of
variables to be placed under one name in a block of memory, allowing the different
variables to be accessed via a single pointer, or the struct declared name which returns
the same address.
• struct directly references a contiguous block of physical memory, usually delimited
(sized) by word-length boundaries.
syntax
struct structure_name
{
data_type member1;
data_type member2;
.
.
data_type memeber;
};
Advantage
• It can hold variables of different data types.
• We can create objects containing different types of attributes.
• It allows us to re-use the data layout across programs.
• It is used to implement other data structures like linked lists, stacks,
queues, trees, graphs etc.
Accessing Structure Members
To access any member of a structure, we use the member access operator
(.). The member access operator is coded as a period between the structure
variable name and the structure member that we wish to access.
Array
Lesson 5
Array
• Arrays are defined as the collection of similar type of data items stored at
contiguous memory locations.
• Arrays are the derived data type in C programming language which can
store the primitive type of data such as int, char, double, float, etc.
• Array is the simplest data structure where each data element can be
randomly accessed by using its index number.