How to Calculate the Size of a Static Array in C++? Last Updated : 18 Mar, 2024 Comments Improve Suggest changes Like Article Like Report In C++, static arrays are the type of arrays whose size is fixed, and memory for them is allocated during the compile time. In this article, we will learn how to calculate the size of a static array in C++. Example: Input:myArray = {1, 2, 3, 4, 5}Output:The size of the array is 5.Size of a Static Array in C++To calculate the size of a static array in C++, we can use the sizeof operator that returns the size of the object in bytes. Syntax to Find the Size of a Static Array in C++arraySize = sizeof(arrayName) / sizeof(arrayName[index]);Here, arrayName is the name of the array.sizeof(arrayName) returns the total size of array in bytes.sizeof(arrayName[index]) returns the size of one element of array.C++ Program to Calculate the Size of a Static ArrayThe following program illustrates how we can calculate the size of a static array using the sizeof operator in C++. C++ // C++ program to illlustrate how to find the size of static // array #include <iostream> using namespace std; int main() { // Initialize an array int arr[] = { 1, 2, 3, 4, 5 }; // Find the size of the array int size = sizeof(arr) / sizeof(arr[0]); // Print the size of the array cout << "The size of the array is: " << size << endl; return 0; } OutputThe size of the array is: 5 Time complexity: O(1)Auxiliary space: O(1) Comment More infoAdvertise with us Next Article How to Calculate the Size of a Static Array in C++? R rohan_paul Follow Improve Article Tags : C++ Programs C++ cpp-array CPP Examples Practice Tags : CPP Similar Reads How to Create a Set of Arrays in C++? In C++, the set container represents a collection of unique, sorted elements, and an array is a collection of items stored at contiguous memory locations. In this article, we will learn about how to create a set of arrays in C++. Set of Arrays in C++A set of arrays refers to a collection of arrays w 2 min read How to Create a Stack of Arrays in C++? In C++, the std::stack is a container that follows the LIFO (Last In, First Out) rule, whereas std::array is a sequence container that stores elements in contiguous memory. In this article, we will learn how to create a stack of an array in C++. Example: Input: arr1 = {1, 2, 3}; arr2 = {4, 5, 6}; ar 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 Find the Cumulative Sum of Array in C++? In C++, the cumulative sum, also known as the prefix sum of an array is the sum of all elements of the array at the current index including the sum of the previous elements. In this article, we will learn how to find the prefix sum of elements in an array in C++. Example Input: arr[]= {1,2,3,4,5} Ou 2 min read How to Create a Vector of Arrays in C++? In C++, an array is a collection of elements of a single type while vectors are dynamic arrays as they can change their size during the insertion and deletion of elements. In this article, we will learn how to create a vector of arrays in C++. Example: Input: arr1 = {1, 2, 3}; arr2 = {4, 5, 6}; arr3 2 min read Like