elibraryportal Logo

Array in C++

An Array is collection of store multiple values in a single variable, instead of declaring separate variables for each value.

What is array in C++

In C++, array index starts from 0.

Advantages of C++ Array

  • Easy to sort data etc.
  • Easy to manipulate data
  • Easy to traverse data
  • Code Optimization (less code)
  • Random Access

Disadvantages of C++ Array

  • Fixed size

Types of Array in C++

There are two types of arrays in C++ programming:

  1. Single Dimensional Array
  2. Multidimensional Array

1) Single Dimensional Array in C++

A single-dimensional array is the simplest from of array that requires only one subscript to access an array element.

Syntax:-

Example:-

Full Example:-

Output:

Enter the marks of your 6 subjects:: 
5
6
7
8
9
10
Average Marks is::7.5

Multidimensional Arrays

Multi-dimensional arrays can be described as arrays of arrays . In multidimensional array store data in tabular form rows and columns

Syntax:-

Example:-

intialisation of two Dimensional Array Example:-

Example:-

Output:

arr[0][0]: 11
arr[0][1]: 22
arr[0][2]: 33
arr[1][0]: 44
arr[1][1]: 55
arr[1][2]: 66

Example:- In C++ Write a Program to calculate sum of two matrices.

Output:

 the resultant matrix is 
   6   8  10
   6   4  14
  14  16   4