Arrays Chapter#04: Bs Computer Science University of Swat
Arrays Chapter#04: Bs Computer Science University of Swat
CHAPTER#04
BS COMPUTER SCIENCE
UNIVERSITY OF SWAT
ARRAYS
• Array is a sequence of objects of same data
type.
• The objects in an array are also called
elements of the array.
• Represented in the computer memory by a
consecutive group of storage locations.
• Referenced by a single variable called array
name.
• Each element is referenced by its position in the
array.
• The position of an element in an array an index
value or subscript.
• array[0] 6
• array[1] ---
• . ---
• . 18
• array[4]
• The above array contain real type data.
• It has five elements
• The first element is array[0] that is in position
0 and the last element is array[4] that is in
position 5-1=4.
:Declaring one-dimensional array
• Defining the name of the array, its type and
the total number of elements of the array is
called declaring of the array.
• Syntax:
• type array-name[n];
• Where ‘n’ is an unsigned integer value,
represent the total number of elements of the
array.
• E.g.,
• double temp[24];
• int abc[5];
• char name[15];
• etc
•
:Accessing data in one-dimensional array
• ( END OF CHAPTER 04 )