

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Why C/C++ array index starts from zero?
As Array index starts with 0, so a[i] can be implemented as *(a + i).
If Array index starts with 1 then a[i] will be implemented as *(a+i-1) which will be time consuming during compilation and the performance of the program will also be effected.
So, it is better to start index of the array from 0.
A simple program of array is given -
Example Code
int main() { int array[5] = {7, 7, 7, 6, 6}; for (int i = 0; i < 5; i++) cout << *(array + i); return 0; }
Output
7 7 7 6 6
- Related Questions & Answers
- Why array index starts from zero in C/C++ ?
- Why does the indexing start with zero in C# arrays?
- Why is address zero used for the null pointer in C/C++?
- Why zero (0) is the first number?
- Picking index randomly from array in JavaScript
- Why is the size of an empty class not zero in C++?
- Overloading array index operator [] in C++
- PHP script to get all keys from an array that starts with a certain string
- Equilibrium index of an array in C++
- Minimum operations to make XOR of array zero in C++
- Remove Zero Sum Consecutive Nodes from Linked List in C++
- Why C treats array parameters as pointers?
- Zero Initialization in C++
- Construct an array from XOR of all elements of array except element at same index in C++
- What is zero figure and why girls are behind to attain this?
Advertisements