-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path19_1D_Array.cpp
More file actions
30 lines (24 loc) · 791 Bytes
/
19_1D_Array.cpp
File metadata and controls
30 lines (24 loc) · 791 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include <iostream>
using namespace std;
/*
Arrays:
Are used to store multiple values.
Syntax:
type identifier[sizeOfArray]; => Example: char myArray[5];
*/
int main(){
char myArray1[5] = {'X', 'Y', 'A', 'B', 'N'}; //Initialization an array
//myArray1 Elements => [A][B][C] => [ ] [ ]...[ ] [ ]
//myArray1 Indices => 0 1 2 => 0 1 n-2 n-1
//Example: myArray1[0] : 'A' or myArray1[2] : 'C'
int myArray2[] = {1, 2, 3, 4, 5, 6, 7};
cout << myArray1[1] << ", " << myArray2[3] << endl;
//Note: size of arrays are fix when they are created, but values can be updated.
myArray1[1] = 'Z';
myArray1[4] = 'T';
//Loop through arrays
for (int i=0; i<5; i++)
{
cout << myArray1[i] << ", ";
}
}