Table of Contents

Array in C++

Arrays in C/C++

  • Difficulty Level : Easy
  • Last Updated : 13 Apr, 2021

An array in C/C++ or be it in any programming language 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.

arrays
Why do we need arrays?
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.
Array declaration in C/C++:



Note: In above image int a[3]={[0…1]=3}; this kind of declaration has been obsolete since GCC 2.5

There are various ways in which we can declare an array. It can be done by specifying its type and size, by initializing it or both.

Ask queries
Contact Us on Whatsapp
Hi, How Can We Help You?