PROGRAMMING FUNDAMENTALS
Lecture-9: Arrays
Dr. Shahid Naseem
Assistant Professor (IT)
Shahid.Naseem@ue.edu.pk
University of Education, Lahore
Arrays
An array is a collection of similar data elements stored at
contiguous memory locations. It is the simplest data structure
where each data element can be accessed directly by only using its
index number.
Arrays can hold the data in the form of numbers, characters,
sentences, Boolean values.
University of Education, Lahore
Arrays
In computer science, an array is a data structure consisting of a
collection of elements, of same memory size, each identified by at
least one array index or key.
An array is stored such that the position of each element can be
computed from its index tuple by a mathematical formula.
An array is represented in the computer memory by a consecutive
group of storage locations referenced by a single variable name
“array name”.
University of Education, Lahore
Arrays
Each element of an array is referenced by its position in the array
and is represented by an index value or subscript.
The subscript of an array is written inside a pair of square brackets [
] with the name of the array.
For example, an array of 10, 32-bit integer variables with indices 0
through 9, may stored as 10 words at-many addresses.
University of Education, Lahore
Arrays
The memory address of the first element of an array is called first
address or foundation address.
An array in a sequence of objects of same data type.
The objects in an array are called “elements of array”.
University of Education, Lahore
Types of Arrays
One-dimensional array
Two/Multi-dimensional array
One-dimensional Array: The simplest type of data structure is a one-
dimensional array. It is also called a linear array or a list.
University of Education, Lahore
Program#29
Write a program that take five numbers in an array and display the
number.
University of Education, Lahore
Program#30
Write a program that take character of a student name in First array,
copy these characters in Second array and display the characters of
second array in the form of student name.
University of Education, Lahore