Since array contains multiple elements, but we have only one variable, we use index to access the elements. The index is nothing but an unique number which identifies each element. Using the index, the element at that index can be initialized or can be read.
![]()
Student Marks Array CODE class StudentMarksArray OUTPUT Third Element = 25 DESCRIPTION In LINE A, we are assigning 25 to the third element i.e. index 2. In LINE B, we are printing third element i.e. also index 2. So it will print the previously assigned value, which is 25. In LINE C, we are printing fourth element i.e. index 3. Since it was not assigned previously, the original default value of 0 is printed. THINGS TO TRY
|