0% found this document useful (0 votes)
45 views12 pages

Arrays in C++

The document discusses arrays including that an array is a group of consecutive memory locations with the same name and type. Each element in an array has a unique index from 0 to the length-1. The document describes declaring, initializing, accessing, and manipulating one dimensional arrays through examples.
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)
45 views12 pages

Arrays in C++

The document discusses arrays including that an array is a group of consecutive memory locations with the same name and type. Each element in an array has a unique index from 0 to the length-1. The document describes declaring, initializing, accessing, and manipulating one dimensional arrays through examples.
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/ 12

Arrays

• An array is a group of consecutive


memory locations with same name and
type.
• The memory locations in the array are
known as elements of array
• The total number of elements in the array
is called its length
Arrays
Each element is accessed with reference
to its position of location in the array.
The position is called the index or
subscript
Each element has a unique index
The index of first element is 0 and the
index of last element is length-1
The value of index is written in brackets
along with the name of array.
Declaring one Dimensional Array
A type of array in which all elements are
arranged in the form of list is known as
one dimensional array. It is also called
single dimensional array or linear list.
The process of specifying the array name,
length and data type is called array
declaration
Syntax
Data_Type Identifier[Length]
 Data_Type: It indicates the type of data.
Identifier: it indicates the name of the
array
Length: Total numbers of elements
in the array.
Example
Int marks[5];

50 55 23 90 32
0 1 2 3 4
Array Initialization
Assigning values to array elements at the
time of array declaration is called array
initialization

Data_Type Identifier[Length]={list of
value}
int marks[5]={70,54,82,96,49}
Accessing Array Elements
IndividualElements
Using loop
Example : scores Array
Array Manupulation
int Ar[10] = {9, 8, 7, 6, 5, 4, 3, 2, 1, 0};
0 1 2 3 4 5 6 7 8 9
Ar 9 8 7 6 5 4 3 2 1 0

Ar[3] = -1;

6 -1

0 1 2 3 4 5 6 7 8 9
Ar 9 8 7 -1 5 4 3 2 1 0
Array Initialization Examples
Array example (find minimum number in array)

main()
{
int arr[5];
int i, min;
for (i=0; i<=4; i++)
{
cout << "enter an integer number: " ;
cin>> arr[i];
cout<<endl;
}
min= arr[0];
for (i=0; i<=4; i++)
if (min > arr[i] )

You might also like