Why Array Index's Start With 0️ ?🤔

Why Array Index’s Start With 0️ ?

An array is essentially a pointer.

What does it mean that an array is a pointer?

Example 1:

Table 1.1
arr[0] = 100 (Address)
arr[1] = 104 (Address)
arr[2] = 108 (Address)
arr[3] = 112 (Address)
100 => 104 => 106 => 108 => 110 => 112

Position = arr[n]

Table 1.2
arr[0] = 100+(1*4)
= 100+4
= 104
But arr[0] should be 100 from Table 1.1
Table 1.3
arr[0] = 100+(0*4)
= 100+0
= 100
arr[0] should be 100 which is same Equal to Table 1.1

Example 2:

// Program to take 5 values from the user and store them in an array// Print the elements stored in the array
#include
<stdio.h>
int main()
{
int mark[5] = {19, 10, 8, 17, 9};
printf("Displaying integers: ");
// printing elements of an array
for
(int i = 0; i < 5; ++i){
printf("%d\n", mark[i]);
}
//Output :- 19,10,8,17,9
for (int j = 0; j < 5; ++j){
printf("%d\n", *(mark + j));
}
//Output :- 19,10,8,17,9return 0;
}
  • * is pointer in C Language
mark = base addressj = (index*bytes)(mark( + j)) = base + (index *  bytes)= 100+(0*4)= 100+0= 100 which is same as again from Table 1.1

The 20 Programming Languages where index’s start from 1 (NOT 0) are:

ALGOL 98APLAWKCFMLCOBOLFortranFoxProJuliaLingoLuaMathematicaMatlabPL/IRPGRRingSassSmalltalkWolfram LanguageXPath/ XQuery

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store