Arrays in C/C++


An array is a collection of similar data items stored at contiguous memory locations and elements can be accessed randomly using indices of an array. They can be used to store collection of primitive data types such as int, float, double, char, etc., of any particular type. To add to it, an array in C/C++ can store derived data types such as the structures, pointers etc.

Given below is the picture representation of an array.


Single -Dimensional Array: The ArraySize must be integer constant greater than Zero and type can be any valid C Data Type.

type ArrayName [ ArraySize ];
double balance [10];


#include <iostream>
#include <string>
using namespace std;

int main() {
  string cars[4] = {"Volvo", "BMW", "Ford", "Ferrari"};
  cout <<"Output of Cars[2] array is " <<" " << cars[2];
  return 0;