0% found this document useful (0 votes)
8 views2 pages

Understanding Arrays in Programming

An array is a static data structure that stores multiple items of the same type at contiguous memory locations, allowing for easy access via indices. In programming, arrays can be declared in various ways, with Python providing specific syntax for creating them. Basic operations on arrays include traversal, insertion, deletion, searching, and updating elements.

Uploaded by

SAM'z SquaD
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views2 pages

Understanding Arrays in Programming

An array is a static data structure that stores multiple items of the same type at contiguous memory locations, allowing for easy access via indices. In programming, arrays can be declared in various ways, with Python providing specific syntax for creating them. Basic operations on arrays include traversal, insertion, deletion, searching, and updating elements.

Uploaded by

SAM'z SquaD
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

What is array?

Arrays are data structures consisting of data items of the same type. That is, an array
is a collection of data items stored at contiguous memory locations.

• Arrays are “static” entities, in that they remain the same size once they are
created.

• The idea of array is to store multiple items of the same type together. This makes
it easier to calculate the position of each element by simply adding an offset to a
base value, i.e., the memory location of the first element of the array.

• An integer array called c.


• This array contains 12 elements.
• A program can refer to any element of an array by giving the name of the array
followed by the position number of the element in square brackets ([]).
• The first element in every array is the zeroth element.
• Thus, the first element of array c is referred to as c[ 0 ], the second element of
array c is referred to as c[ 1 ].
• The position number in square brackets is more formally called a subscript (or an
index). A subscript must be an integer or an integer expression.

Arrays can be declared in various ways in different languages.

Python:
from array import *

myarray=array('d', [3.0,8.5,4.7,9.0,20.6])

or

import array as arr

myArray= [Link]('i', [1,1,3,5,2])

Python arrays: Array is a container which can hold a fix number of items/elements of
the same type.

Following are the important terms to understand the concept of Array.


• Element− Each item stored in an array is called an element.
• Index − Each location of an element in an array has a numerical index, which
is used to identify the element
Elements

myArray= [Link]('i', [1,1,3,5,2])

Name Data type Index 2

Following are the important points to be considered.


• Index starts with 0.
• Array length is 5 which means it can store 5 elements.
• Each element can be accessed via its index. For example, we can fetch an
element at index 2 as 3.

Some Basic Operations on array:


• Traverse − Explore/print all the array elements one by one.
• Insertion − Adds an element at the given index.
• Deletion − Deletes an element at the given index.
• Search − Searches an element using the given index or by the value.
• Update − Updates an element at the given index.

You might also like