How to Print an Array in C++? Last Updated : 12 May, 2024 Comments Improve Suggest changes Like Article Like Report Try it on GfG Practice 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 Array Elements in C++ To print array elements in C++, we can use a simple for loop to iterate over the elements of the array and print each element while iterating. This allows us to print the whole array without using a single statement for printing single element. C++ Program to Print an Array C++The below program demonstrates how we can use a simple for loop to iterate over the array elements and print each one. C++ // C++ program to print an array #include <iostream> using namespace std; int main() { // Intializing an Array int array[] = { 10, 20, 30, 40, 50 }; // finding size of array int n = sizeof(array) / sizeof(array[0]); // Print the array cout << "Array Elements: "; for (int i = 0; i < n; i++) cout << array[i] << " "; cout << endl; return 0; } OutputArray Elements: 10 20 30 40 50 Time Complexity: O(N), where N is the size of the array.Auxilliary Space: O(1) Note: We can also use range based for loop in C++11 and later to iterate through the array and print each element. Comment More infoAdvertise with us Next Article How to Print an Array in C++? K krahuld77u Follow Improve Article Tags : C++ Programs C++ cpp-array C++ Array Programs CPP Examples +1 More Practice Tags : CPP Similar Reads How to Sort an Array in C++? Sorting an array involves rearranging its elements in a specific order such as from smallest to largest element or from largest to smallest element, etc. In this article, we will learn how to sort an array in C++.Example:Input: arr ={5,4,1,2,3}Output: 1 2 3 4 5Explanation: arr is sorted in increasin 4 min read How to Initialize an Array in C++? 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 assignmen 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 How to Resize an Array of Strings in C++? In C++, the array of strings is useful for storing many strings in the same container. Sometimes, we need to change the size of this array. In this article, we will look at how to resize the array of strings in C++. Resize String Array in C++There is no way to directly resize the previously allocate 2 min read How to Declare an Array in C++? In C++, an array is a collection of similar data types in which elements are stored in contiguous memory locations. In this article, we will learn how to declare an array in C++. Declaring an Array in C++In C++, we can declare an array by specifying the type of its elements, followed by the name of 2 min read Like