Array elements are accessed by using an integer index. Array index starts with 0 and goes till size of array minus 1.
We can use normal variables (v1, v2, v3, ..) when we have a small number of objects, but if we want to store a large number of instances, it becomes difficult to manage them with normal variables. The idea of an array is to represent many instances in one variable.
Advantages of an Array in C/C++:
- Random access of elements using array index.
- Use of fewer line of code as it creates a single array of multiple elements.
- Easy access to all the elements.
- Traversal through the array becomes easy using a single loop.
- Sorting becomes easy as it can be accomplished by writing fewer line of code.