Title: ARRAY IN C++
1OBJECT ORIENTED PROGRAMMING LANGUAGE
ARRAYS
PRESENTATION BY Aniruth S RA2211030050043 Object
Oriented Programming
2DEFINITION OF ARRAY
DECLARATION OF ARRAY
ADVANTAGES OF ARRAY
EXAMPLE PROGRAM
TYPES OF ARRAY
DEFINITION OF 1D-ARRAY
3EXAMPLE PROGRAM
DEFINITION OD 2D-ARRAY
EXAMPLE PROGRAM
STRING AS ARRAY
REAL WORLD EXAMPLES
REFERENCE
4(No Transcript)
5DECLARATION OF ARRAY
Like a regular variable, an array must be declared before it is used. A typical declaration for an array in Visual C istype name elements type is a valid type (like int, float...) name is a valid identifier elements field (which is always enclosed in square brackets ), specifies how many of these elements the array has to contain
6(No Transcript)
7include ltiostreamgt using namespace std int
main() // declare an integer array of size
5 int arr5 // initialize the array
with some values arr0 10 arr1
20 arr2 30 arr3 40 arr4
50 // print the values of the array
for (int i 0 i lt 5 i) cout ltlt
"arr" ltlt i ltlt " " ltlt arri ltlt endl
return 0
8arr0 10 arr1 20 arr2 30 arr3
40 arr4 50
9TWO DIMENSION ARRAY(2-D ARRAY)
SINGLE DIMENSION ARRAY(1-D ARRAY)
10DEFINITION
A one dimensional array is one in which one subscript /indices specification is needed to specify a particular element of array
DECLARATION
Data_type array_name size of array
EXAMPLE
Int num10
1-D ARRAY
11include ltiostreamgt using namespace std int
main() const int size 5 // constant size
of the array int arrsize // declaring an
integer array of size 5 // initializing
array elements using a for loop for(int i0
iltsize i) cout ltlt "Enter element " ltlt
i1 ltlt " " cin gtgt arri //
printing array elements using a for loop cout
ltlt "\nArray elements are " for(int i0
iltsize i) cout ltlt arri ltlt " "
return 0
12Enter element 1 10 Enter element 2 20 Enter
element 3 30 Enter element 4 40 Enter element
5 50 Array elements are 10 20 30 40 50
13DEFINITION
A 2-d array is an array in which each element is itself an array
DECLARATION
int num43
EXAMPLE
1 2 3 4
2-D ARRAY
14include ltiostreamgt using namespace std int
main() const int ROWS 3 const int
COLS 3 int arrROWSCOLS //
initializing array elements using nested for
loops for(int i0 iltROWS i)
for(int j0 jltCOLS j) cout ltlt
"Enter element (" ltlt i ltlt ", " ltlt j ltlt ") "
cin gtgt arrij //
printing array elements using nested for loops
cout ltlt "\nArray elements are \n" for(int
i0 iltROWS i) for(int j0 jltCOLS
j) cout ltlt arrij ltlt " "
cout ltlt endl return 0
15Enter element (0, 0) 1 Enter element (0, 1)
2 Enter element (0, 2) 3 Enter element (1, 0)
4 Enter element (1, 1) 5 Enter element (1, 2)
6 Enter element (2, 0) 7 Enter element (2, 1)
8 Enter element (2, 2) 9 Array elements are 1
2 3 4 5 6 7 8 9
16https//grasshopper.app/why-coding/
https//www.computerscience.org/resources/what-is-coding-used-for/
https//en.wikipedia.org/wiki/Coding
https//code.org/
https//careerkarma.com/blog/what-is-coding-used-for/
https//kandi.openweaver.com/
17(No Transcript)