How to Find the Size of a Set in Bytes in C++? Last Updated : 22 Feb, 2024 Summarize Comments Improve Suggest changes Share Like Article Like Report In C++, sets are associative containers that only store unique elements. The elements inside the set are sorted in a specific order. In this article, we will learn how we can find the size of a set in bytes in C++. Example Input: S = {1,2,3,4}Output: Size of the set in bytes is : 16Find the Size of a Set in Bytes in C++ We can find the size (number of elements) of a set using the std::set::size() method easily, however, C++ doesn't have any method that can find the size of a set in bytes. To find the size of a set in bytes, we can multiply the number of elements by the size of each element. We can find the size of each element using sizeof() operator. C++ Program to Find the Size of a Set in Bytes C++ // C++ Program to Find the Size of a Set in Bytes #include <iostream> #include <set> using namespace std; int main() { // Initialize a set with some elements set<int> s = { 1, 2, 3, 4 }; // Calculate the size of the set int setSize = s.size(); // Calculate the size of any individual element in the // set by dereferencing the iterator int elementSize = sizeof(*s.begin()); // Calculate the size of the set in bytes int size = setSize * elementSize; cout << "Size of the set in bytes is : " << size << endl; return 0; } OutputSize of the set in bytes is : 16 Time Complexity: O(1)Auxiliary Space: O(1) Comment More infoAdvertise with us Next Article How to Find the Size of a Vector in Bytes in C++? G gaurav472 Follow Improve Article Tags : C++ Programs C++ STL cpp-set CPP Examples +1 More Practice Tags : CPPSTL Similar Reads How to Find the Size of a Map in Bytes in C++? In C++, maps are associative containers that store a key value and a mapped value for each element and no two mapped values can have the same key values. In this article, we will explore how to find the size of the map in bytes in C++. Example Input: myMap = {{âappleâ, 1}, {âbananaâ, 2}, {âcherryâ, 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 Find the Size of a Vector in Bytes in C++? In C++, Vectors are dynamic containers that can change their size during the insertion or deletion of elements. In this article, we will explore how we can find the size of the vector in bytes in C++. Example: Input:myVector = {10,20,30,40,50}Output:Size of the vector in bytes is : 20 bytesFind the 2 min read How to Find the Size of a List in C++? In C++, Standard Template Library (STL) we have a std::list container that is a doubly-linked list in which elements are stored in non-contiguous memory allocation. In this article, we will learn how to find the size of a list in C++ STL. Example: Input: myList = {10, 20, 30, 40, 50}; Output: Size o 2 min read How to Find the Size of a Map in C++? In C++ STL, maps are associative containers that store elements in a mapped fashion. Each element has a key value and a mapped value. No two mapped values can have the same key values. In this article, we will learn how to find the size of a map in C++ STL. Example: Input: myMap = { {1, "Sravan"}, { 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 Like