Chapter 7 Arrays
Array An array is a collection of similar elements one variable ⇒ capable of storing multiple values Syntax The syntax of declaring an array looks like this. Int marks[90]; ⇒ Integer array char name[20]; ⇒ character array or strong float percentile[90]; ⇒ float array The values can now be assigned to marks array like this : marks [0] ⇒33; marks [1] ⇒12; NOTE; It is very important to note that the array index starts with 0 marks → 7,6,21,3,91,3,.,.,.,88,89 0 1 2 3 4 5 . . . 88 89 Total = 90 elements Accessing elements Elements of an array can be accessed using ; scanf(”%d”,&marks[0]); ⇒ Input first value printf(”%d”,marks[0]); ⇒ Output first value of the array Initialization of an array There are many other ways in which an array can be initialized. int cgpa [3] = {9,8,8} ⇒ Array can be initialized while declaration float marks[] = {33,40} Arrays in memory Consider this array; int arr [3]={1,2,3} ⇒ 1 integer =4bytes This wil...