Save
AMAT 152 Finals
Struct
Save
Share
Learn
Content
Leaderboard
Learn
Created by
nathalie
Visit profile
Cards (17)
Array
A collection of elements of the same
data type
Structure
A collection of one or more elements grouped under a single name for easy
manipulation
Can contain elements of
different
data types
Struct
Keyword that identifies the
beginning
of a structure
Writing a structure
1.
Struct
keyword
2.
Name
of the structure
3.
Members
of the structure enclosed in
braces
4.
Semicolon
to end the structure
Structure instance
Declaring
structure
variables after writing the structure definition
Accessing structure members
Using the
dot operator
(.) between the
structure variable
name and the structure member name
Copying information between
structures
Possible to
copy
information between
structures
of the same type
Initializing
structure members
Can initialize member elements at
declaration
Complex
structures
Structures containing other
structures
as
members
Structures containing arrays as
members
Accessing members of structures inside structures
Use
dot
operator to access nested
structure
members
A
structure
can be considered as a type for a
variable
(instance of the structure)
Structure member elements
cannot
be initialized with values on the definition of the
structure
Structures containing
arrays
Structure can contain one or more
arrays
as members
Access array elements using
structure
variable
name
and dot operator
Array
of
structures
Can have
arrays
of
structures
Access
members using structure variable name,
dot
operator, and array index
Initializing structure instances
1. Can initialize
simple
structures at
declaration
2. Can initialize
complex
structures at
declaration
Passing structures to functions
Can pass structures by
value
or by
reference
Passing arrays of
structures
to
functions
is similar to passing ordinary arrays