Search⌘ K

Creating an Array

Explore how to create and initialize arrays in C++. Learn to declare arrays with specified sizes, assign values using different approaches, and understand default initialization of elements. This lesson gives you the fundamentals needed to work with arrays and prepares you to access and update array elements effectively.

Introduction

An array is a collection of elements of the same data type a the single name. Let’s see how we can declare and initialize an array in C++.

Array declaration

The general syntax for declaring an array is given below:

In the array declaration, we specify the data type followed by an array name, which is then followed by an array size in square brackets.

See the code given below!

C++
#include <iostream>
using namespace std;
int main() {
int Roll_Number[5];
}

We declare an array Roll_Number that can store 5 integer ...