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 How to Find the Size of a Dynamically Allocated Array in C++? In C++, dynamic memory allocation enables the users to manage the memory resources during the execution of the program and is very useful for arrays when the size of the array is not known at compile time or during any other times for flexibility. In this article, we will learn how to find the size 2 min read How to Create a 2D Array of a Specific Size and Value in C++? In C++, a 2D array is an array of arrays that stores data in the form of a grid with rows and columns. In this article, we will learn how to create a 2D array of a specific size and fill it with some value in C++. Example Input: rows = 3; columns = 3; value = 1; Output: 2D Array: { {1, 1, 1}, {1, 1, 2 min read How to Find the Size of a Deque in C++? In C++, deque also known as double-ended queues are containers that allow efficient insertion and deletion operations from both ends of the deque. In this article, we will learn how to find the size of a deque in C++. Example: Input: myDeque = {10, 20, 30, 40, 50} Output: Size of the Deque is: 5Find 2 min read How to Find the Size of a Set in C++? In C++, sets are STL containers that store unique elements of the same type in a sorted manner. No duplicate elements are allowed in the sets, as the value of every element in a set is unique. In this article, we will learn how we can find the size of a set container in C++. Example: Input: mySet={1 2 min read How to Create Array of Arrays in C++ Arrays are basic C++ data structures that allow users to store the same data type in memory sequentially. To manage more complicated data structures, you may sometimes need to build an array of arrays, often called a 2D array or a matrix. In this article, we will learn how to create an array of arra 3 min read Like