Prerequisite : Pointers in C/C++
Consider int arr. The answer lies in the fact how the compiler interprets arr[i] ( 0<=i<100).
arr[i] is interpreted as *(arr + i). Now, arr is the address of array or address of 0th index element of array. So, address of next element in array is arr + 1 (because elements in array are stored in consecutive memory locations), further address of next location is arr + 2 and so on . Going with above arguments, arr + i means address at i distance away from starting element of array. Therefore, going by this definition, i will be zero for starting element of array because starting element is at 0 distance away from starting element of array. To fit this definition of arr[i], indexing of array starts from 0.
The conclusion is, we need random access in array. To provide random access, compilers use pointer arithmetic to reach i-th element.
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Why is the size of an empty class not zero in C++?
- Why C treats array parameters as pointers?
- C program to Check Whether a Number is Positive or Negative or Zero
- Zero Initialization in C++
- Why copy constructor argument should be const in C++?
- Why "&" is not used for strings in scanf() function?
- Why C++ is partially Object Oriented Language?
- Why is a[i] == i[a] in C/C++ arrays?
- Why is C considered faster than other languages ?
- Why variable name does not start with numbers in C ?
- Why only subtraction of addresses allowed and not division/addition/multiplication
- Why strict aliasing is required in C ?
- Why we should avoid using std::endl
- Why "using namespace std" is considered bad practice
- Why does sizeof(x++) not increment x in C?
- Why strcpy and strncpy are not safe to use?
- Why are elementwise additions much faster in separate loops than in a combined loop?
- Why learning C Programming is a must?
- Why to use fgets() over scanf() in C?
- Why overriding both the global new operator and the class-specific operator is not ambiguous?
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.