Most of us (programmers) might have wondered why an index starts with a whole number ‘0’. what is the starting index of an array in c? ‘array starts from 0 or 1’
Let’s start:
Introduction
In C, the index of an array begins with 0 (as opposed to 1), which may seem strange at first glance. Although you may be tempted to think that it’s the same as in Java or Python, this is not the case. To understand why the index starts with 0 and not 1, we must first take a look at how arrays are implemented in C.
First Known Use of 0 by the Ancient Babylonians
The use of zero as a place holder in counting appears to have first been used by Indian scholars around AD 500. The concept then spread from India to other regions through trade and religious conversion, and made its way to Europe in 600 A.D., where it became an accepted mathematical practice by about 1200 A.D. The word zero comes from Arabic, meaning empty. In English, we refer to it as oh, which was derived from zephirum, another Arabic word for zero. Today we use zero every day without thinking twice about it; however, had things turned out differently in history, we might be saying one instead!
First Written Evidence from Hero of Alexandria
The first known mathematical reference to array indexes is from Hero of Alexandria, who in his work, Pneumatics, described an odometer-like device that used rotating gears to count wheel rotations. The written description of it is one of the oldest examples of someone using a number as both an index and address, which led computer scientists and mathematicians to believe that it was based on counting up, rather than counting down.
Shift from Numerical Indices to Alphabetical Indices
It is common to see numerical indices being used to reference positions in an array, for example: myArray[0], myArray[1], myArray[2]. However, by using alphabetical indices such as myArray[A], myArray[B], and so on, we can retrieve our data much more quickly. This is because there are 26 alphabets letters and they can be accessed sequentially, unlike numeric indices where accessing subsequent numbers takes significantly longer. Instead of taking 100 nanoseconds to access successive items in an array (for each item x), alphabetical indices take only 5-6 nanoseconds per item.
Change in Number System Over Time
The number system we use today, called Arabic numerals or Hindu-Arabic numerals, is based on ten and positional notation. We start counting with zero and go up from there. It wasn’t always that way. There was a time when numbers were actually represented in words rather than symbols, though in some cases it’s difficult to say what exactly those symbols meant to people who used them. For example, there are instances of evidence for ancient people using special symbols for 2 and 5, but it isn’t clear whether these were just names for those numbers or if they meant something else entirely.
Use of Maths in Programming
Indexing and Slicing, we find an array starting from 0 or 1 makes no difference in coding it. The array starts from first index in C++ at Index 0. There are 2 ways to define Arrays; as integers, as float etc. In both cases, they start from index 0. So why do arrays start with index 0 when they could have started with index 1? For example: int i = 5; // This is Index 5 of array int j = 6; // This is Index 6 of array When you want to access any element of an Array using its index number (i), you can use one of two methods:
Arithmetics
Most of us are familiar with hexadecimal numbers, whether we’re computer engineers or system administrators. Most of us use it to represent IP addresses and Unicode strings for displaying in HTML documents. It is also possible to define an integer that can hold negative values as well as positive ones. In fact, you probably do so already if you use a multi-byte variable or int64_t on your system (see What Every Programmer Should Know About Floating Point Arithmetic). Although it is theoretically possible to have a value less than zero in an unsigned number, many people think that it makes more sense to have zero at index number one when dealing with arrays and are surprised to find out that indexing actually starts from zero instead of one.
Credit:- AryaBhata(Ancient Indian Astronomer)