Array in C++
The array is a collection of data that store the fixed number of values of the same type.
Syntax:-
type array_Name [ array_Size ];
Example:
if we want to store marks of 100 students, then we can create an array for it.
float marks[100];
Size and type of arrays cannot change after it's declared.
Two types of Arrays:
- One-dimensional arrays
- Multidimensional(2D) arrays

Array Type | Description |
---|---|
Single Dimensional array | In this we create and initialize all the values in the single array. |
Multi-Dimensional Array | C++ supports the multi-dimensional array. The multi-dimensional array also called as the Two-Dimensional array. |
Pointer to an array | You can generate and use the pointer to the first element by simply specifying the array name without declaring any index. |
Passing arrays to function | You can pass to the function of a pointer to an array by specifying the array name. |
Return array of functions | It allows a function to return an array. |
Advantages of an array:
- It is better to store the data of the same data type with the same size.
- Coding is less, one variable can store a number of values.
- It allocates memory in different memory locations for its elements. There is no memory flow or shortage of memory in arrays.
- Iterating is faster in arrays compared to other methods like a linked list.
- By using array data retrieving is easy.
- Easily short the data using the swapping method.
- By array index, we can randomly access any element from the array.
- It supports multidimensional array.
Array Declaration in C++
To declare an array in C++ programming language.
Syntax:-
data_type array_name[array_size];
Array Initialization in C++
An array is initialized by using the index of each element.
Syntax:-
int score[4] = {100, 221, 59, 54};
Example:-
#include <iostream> using namespace std; int main(){ int i=0; int score[4] = {100, 221, 59, 54}; for(i=0; i<4; i++){ cout << " Element[" << i << "]= " << score[i] << endl; } }
Quickly Find What You Are Looking For
OnlineTpoint is a website that is meant to offer basic knowledge, practice and learning materials. Though all the examples have been tested and verified, we cannot ensure the correctness or completeness of all the information on our website. All contents published on this website are subject to copyright and are owned by OnlineTpoint. By using this website, you agree that you have read and understood our Terms of Use, Cookie Policy and Privacy Policy.