0% found this document useful (0 votes)
9 views15 pages

Data Structures and Algorithms-Module-1-part2

The document discusses arrays in C++ including defining, initializing, traversing, inserting, deleting, and dynamically allocating arrays. It also mentions arrays can hold elements of the same type and have indexes for each element location.
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)
9 views15 pages

Data Structures and Algorithms-Module-1-part2

The document discusses arrays in C++ including defining, initializing, traversing, inserting, deleting, and dynamically allocating arrays. It also mentions arrays can hold elements of the same type and have indexes for each element location.
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/ 15

19EAC203 Data Structures

and Algorithms
Dr. Nimmy K
Assistant Professor
Department of Computer Science and Engineering
Amrita Vishwa Vidyapeetham, Amritapuri
Arrays
• An array is a collection of similar type of items stored at contiguous
memory locations.

• Elements: Each item stored in an array.


• Index: Each location of an element in an array has a numerical index.
Array: Insertion Operation
Array: Deletion Operation
Declaring Array in C++
• To declare an array in CPP, need to specifies the type of the elements and the number
of elements required by an array as follows
type arrayName [ arraySize ];
• Single-dimensional array.
• The arraySize must be an integer constant greater than zero and type can be any valid C++ data
type
Eg: float balance[10];
• balance is an array which is sufficient to hold up to 10 float numbers.
Initializing an Array
• It is possible to initialize an array during declaration
int mark[5] = {19, 10, 8, 17, 9};
int mark[] = {19, 10, 8, 17, 9};
Example 1: Traversal
C++ Dynamic Allocation of Arrays

• In C++, a dynamic array can be created using new keyword and can be
deleted it by using delete keyword.
• int *a = new int(n);
• The allocated memory must be deleted using the delete[] operator.
Output
• Write the above program in OOP.
Output:

You might also like