0% found this document useful (0 votes)
56 views11 pages

ARRAY in C++: Kristina Jonas E. Mendoza

An array is a collection of similar data types stored in contiguous memory locations that can be accessed using an index. Arrays allow storing and manipulating multiple values using a single name. A one-dimensional array stores elements in a linear list, accessed using a single index. Elements are initialized and accessed using indexing and loops. A two-dimensional array stores elements in a table structure with rows and columns accessed using two indexes.

Uploaded by

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

ARRAY in C++: Kristina Jonas E. Mendoza

An array is a collection of similar data types stored in contiguous memory locations that can be accessed using an index. Arrays allow storing and manipulating multiple values using a single name. A one-dimensional array stores elements in a linear list, accessed using a single index. Elements are initialized and accessed using indexing and loops. A two-dimensional array stores elements in a table structure with rows and columns accessed using two indexes.

Uploaded by

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

ARRAY in C++

Kristina Jonas E. Mendoza


What is an array?
• a simple variable is a single memory location with a unique name and
a type, but an array is a group of consecutive memory locations with
the same name and data type
Uses of array
• Arrays can store a large number of value with a single name.
• Arrays are used to process many values easily and quickly.
• The values stored in an array can be sorted easily.
• The search process can be applied on arrays easily.
Parts of an array
• The memory locations in the array are known as elements.
• The total number of elements in the array is called length.
• The elements of array is accessed with reference to its position in the
array, that is called the index or subscript.
0 1 2 3 4

int arrayname[5]
One-dimensional array
• A type of array in which all elements are arranged in the form of a list
is known as a 1-D array or single dimensional array or linear list.
• Declaring a single dimensional array:
data_type identifier[length];
• Example:
int samplearray[5];
Initializing a one-dimensional array
• The process of assigning values to array elements at the time of array
declaration is called array initialization.
• Syntax:
data_type identifier[length]={ list of values };
• Example:
int samplearray[5]={10,20,30,40,50};

0 1 2 3 4

int samplearray 10 20 30 40 50
Accessing elements of an array
• Individually
array_name[index];
• Example:
samplearray[2];
• Using loop
for (n=0; n<5; ++n) {
cout<<samplearray[n]<<endl;
}
Example programs
• Display individually
• Display using loop
• Compute the average of entered values
Two-dimensional array
• 2-D array can be considered as a table that consists of rows and
columns. Each element in 2-D array is referred with the help of two
indexes. One index indicates row and second indicates the column.
• Declaration:
data_type Identifier[row][column];
• Example:
int samplearray[3][4];
Syntax:
int samplearray[3][4]={ {12,5,22,30},{95,3,41,50},{77,6,53,45}};

0 1 2 3

0 12 5 22 30

1 95 3 41 50

2 77 6 53 45

You might also like