How to Initialize an Array in C++? Last Updated : 18 Mar, 2024 Comments Improve Suggest changes Like Article Like Report In C++, an array is a collection of similar datatypes stored in contiguous memory locations in which each element can be accessed using their indices. In this article, we will learn how to initialize an array in C++. Initializing an Array in C++To initialize an array in C++, we can use the assignment operator = to assign values to the array at the time of declaration. The values are provided in a comma-separated list enclosed in curly braces {}. Syntax to Initialize an Array in C++We can use the below syntax to initialize an array at the time of declaration. datatype arrayName[arraySize] = {element, element2, ..., elementN};C++ Program to Initialize an ArrayThe below program illustrates how we can initialize an array in C++. C++ // C++ Program to illustrate how to initialize an array #include <iostream> using namespace std; int main() { // Initialize an array using initializer list int arr[5] = { 10, 20, 30, 40, 50 }; // Find the size of the array int size = sizeof(arr) / sizeof(arr[0]); // Print the elements of the array cout << "Array Initialized" << endl; cout << "Array Elements:"; for (int i = 0; i < size; i++) { cout << arr[i] << " "; } return 0; } OutputArray Initialized Array Elements:10 20 30 40 50 Time Complexity: O(N), here N denotes the number of elements in the array.Auxiliary Space: O(1) Comment More infoAdvertise with us Next Article How to Initialize an Array in C++? A aayushi2402 Follow Improve Article Tags : C++ Programs C++ cpp-array CPP Examples Practice Tags : CPP Similar Reads How to Initialize a Dynamic Array in C++? In C++, dynamic arrays allow users to allocate memory dynamically. They are useful when the size of the array is not known at compile time. In this article, we will look at how to initialize a dynamic array in C++. Initializing Dynamic Arrays in C++The dynamic arrays can be initialized at the time o 1 min read How to Initialize a Set with an Array in C++? In C++, an array stores data in contiguous memory locations and can have duplicates as well whereas a set stores unique elements only in a sorted order. In this article, we will learn how to initialize a set with an array in C++. For Example, Input:arr[]={2, 1, 5, 4, 3, 5};Output:Element in Set are: 2 min read How to Print an Array in C++? In C++, an array is a fixed-size linear data structure that stores a collection of elements of the same type in contiguous memory locations. In this article, we will learn how to print an array in C++. For Example, Input: array = {10, 20, 30, 40, 50}Output: Array Elements: 10 20 30 40 50Printing Arr 2 min read How to Initialize Vector of Char Arrays in C++? In C++, a vector is a dynamic array that can grow and shrink in size. A char array is a sequence of characters, typically used to represent strings. In this article, we will learn how to initialize a vector of char arrays in C++. Example: myVector: {âappleâ, âbananaâ, âcherryâ}Initializing a Vector 2 min read How to Loop Over an Array in C++? In C++, an array is a data structure that stores elements of similar type in contiguous memory locations. We can access the elements of an array using array indexing. In this article, we will learn how to loop over an array in C++. Example: Input: int arr[] = [1, 2, 3, 4, 5] Output: Array Elements: 2 min read Like