Module 03 Array
Module 03 Array
MODULE 03
Arrays
Let’s have an
Ice Breaker
Are you ready???
ARRAYS
Topic Objectives
● Be introduced to arrays;
● Understand the need of arrays;
● Determine the different types of arrays;
● Initialize arrays;
● Initialize unsized arrays; and,
● Use strings as an array.
Introduction
Introduction
An array is a collection of variables that can hold value of
the same type and reference by common name. It is a
derived data structure. Arrays are always stored in a
continuous memory location. Array data types can either
be an integer, a character, or float base type. We need
arrays to store processed large number of variables of same
data type and reference/name. With the help of arrays, we
can easily understand a program
CS 131: Data Structures and Algorithms
Batangas State University The National Engineering University – Mabini Campus
TYPES OF ARRAYS
Types of Arrays
One – Dimension Arrays
A one- dimensional array is when one subscript/indices
specification is needed to specify a particular element of
array
Array Initialization
Line 6 is the initialization. As you can see, the array name is of integer data type,
has a size of 12, and has. If you will notice, I used a do-while loop to display all of
the elements of the array. The variable x is the indices. Using that code, the output
will be:
Two-dimensional arrays are also initialized in the same way as linear arrays. For
example,
Multi-Dimensional Arrays
CS 131: Data Structures and Algorithms
Batangas State University The National Engineering University – Mabini Campus
Strings as Arrays
C++ does not have a string data type, it impairments string
as a one-dimensional character array. A string as a character
array is terminated by a null character, '\0'.
Summary
● An array is a collection of variables that can hold value of the same data type and
reference by a common name.
● Indexing in array starts from zero, and the highest address corresponds to the last element.
● Arrays are needed to store processed large number of variables of the same data type and
name.
● Arrays with 3 or more dimensions are not often used because of its complexity and huge memory
requirement.
Summary
● In C++, the facility of array initialization at the time of declaration is provided.
● Two-dimensional arrays are initialized the same way as linear arrays.
● C++ enables you to skip the size of an array in the initialization statement. It
automatically creates an array that is big enough to hold the initializers
present.
● If the size is skipped, the initializers should be given, so that C++ can
calculate the array size.
Thank You ☺