
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
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
Advertisements