You are on page 1of 12

Data Structure

Lecture 0
Revision
 Revision to some concepts of OOP
 Arrays
 Pointers
Arrays

 Group of consecutive memory location.


 Total number of elements in the array is called its length.
 Store a large number of values with same name and type.
 Sorting and searching operation can be applied on arrays easily.
Arrays

 Declaration of an array.
 Initialization of an array.
 Accessing single element of an array.
 Accessing elements of an array using Loops.
 Input and Output values of an array.
Write a program that inputs five integers from the
user and stores them in an array. It then display all
the values in the array using loops.
Solution
 Void main() {
 Int arr[5], i;
 For(i=0, i<5, i++){
;”:Cout<< “Enter an integer
};Cin >> arr[i]
 Cout<< “values of an array are:”
 For(i=0, i<5, i++){
;Cout<< arr[i]<<endl
 getch();
 }
Types of Arrays

 1-Dimensional Array
 2-Dimensional Array
 Multidimensional Array
D Array-2

 Declaration of 2-D array.


 Initialization of 2-D array.
 Accessing individual value of 2-D array.
 Input and Output values of 2-D array.
Write a program that stores integer values
in an array of 2 rows and 4 columns.
Solution
 Void main() {
 Int arr[2][4], i,j;
 For(i=0, i<2, i++){
{For(j=0; j<4; j++)
;”:Cout<< “Enter an integer
}};Cin >> arr[i][j]
 Cout<< “values of 2-D array are:”
 For(i=0, i<5, i++){
{For(j=0; j<4; j++)
;”Cout<< arr[i][j]<<“\t

}};Cout<<endl
 getch();
 }
Multidimensional Array

 Array of arrays.
 Can have three, four or more dimensions.
 Rapidly increases the amount of memory required with each dimension.
References

 Book: Object Oriented Programming using C++


 https://www.programiz.com/c-programming/c-arrays

You might also like