4.arrays
TRANSCRIPT
![Page 1: 4.arrays](https://reader035.vdocument.in/reader035/viewer/2022071816/55abeed01a28ab4f318b480b/html5/thumbnails/1.jpg)
Arrays
What you’ll learn:
o Defining and using arrays
o Defining and using strings
![Page 2: 4.arrays](https://reader035.vdocument.in/reader035/viewer/2022071816/55abeed01a28ab4f318b480b/html5/thumbnails/2.jpg)
What is an array ?
An array is a collection of variables of the same type that are referenced by a common
name.
They are a derived data type.
We can divide arrays into two types:
Single Dimensional (1-D) arrays
Multi Dimensional arrays
![Page 3: 4.arrays](https://reader035.vdocument.in/reader035/viewer/2022071816/55abeed01a28ab4f318b480b/html5/thumbnails/3.jpg)
Single Dimensional Arrays
1 2 3
int arr [5] = { 1, 2, 3, 4, 5 };
Syntax: base_type array_name [size];
Size
Array name Initialization
Base Type
Memory:
4000 4016 4020
4 5
4004
Total Size:
4 X 5 = 20
![Page 4: 4.arrays](https://reader035.vdocument.in/reader035/viewer/2022071816/55abeed01a28ab4f318b480b/html5/thumbnails/4.jpg)
Multi Dimensional Arrays
1 2 3 4 5
int arr [3][2] = { {1,2}, {3,4}, {5,6} };
Syntax: base_type array_name [rows][columns];
Size
Array name Initialization
Base Type
Memory
4000 4020 4024
6
4004
Total Size:
4 X 6 = 241 2
3 4
5 6
4008
4016
4000
![Page 5: 4.arrays](https://reader035.vdocument.in/reader035/viewer/2022071816/55abeed01a28ab4f318b480b/html5/thumbnails/5.jpg)
Strings
‘H’ ‘e’ ‘l’ ‘l’
char str[] = “Hello”;
Syntax: char array_name [size];
Size
String name Initialization
Memory:
4000 4005 4006
‘o’ ‘\0’
4001
Total Size:
1 X 6 = 6