0% found this document useful (0 votes)
18 views

Lec 11

This document discusses structures in computer programming. Structures allow grouping of related variables of different data types under a single name. This helps organize complicated data, especially in large programs, by treating grouped variables as a single unit rather than separate entities. A structure contains multiple data types and can be declared by specifying the data types. Individual elements within a structure are accessed using the structure name and element name joined by a period. Structures can also be nested by making elements themselves structures, and can include arrays.

Uploaded by

toin4m
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views

Lec 11

This document discusses structures in computer programming. Structures allow grouping of related variables of different data types under a single name. This helps organize complicated data, especially in large programs, by treating grouped variables as a single unit rather than separate entities. A structure contains multiple data types and can be declared by specifying the data types. Individual elements within a structure are accessed using the structure name and element name joined by a period. Structures can also be nested by making elements themselves structures, and can include arrays.

Uploaded by

toin4m
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

CST 281­1

Computer Programming
Laboratory Session 11
Structures
 A structure is a collection of one or more
variables, possibly of different types, grouped
together under a single name for convenient
handling. (Structures are called ``records'' in
some languages.)

 Structures help to organize complicated data,


particularly in large programs, because they
permit a group of related variables to be treated
as a unit instead of as separate entities.
Structures
 A STRUCTURE contains a number of data types
grouped together. These data types may not be of the
same type.
Declaration: (Example)
struct employee
{
int emp_no;
char name[20];
float salary;
} emp1,emp2,emp3;
Accessing Structure Elements
 Example:
emp1.emp no;
emp1.name;
emp1.salary;

emp2.emp_no;
emp2.name;
emp2.salary
Example of a structure

 The payroll record: an employee is described


by a set of attributes such as name, address,
social security number, salary, etc. Some of
these in turncould be structures: a name has
several components, as does an address and
even a salary.
Structures Example
Nested Structures
Structures with Array
END

You might also like