Why does empty Structure has size 1 byte in C++ but 0 byte in C Last Updated : 04 Aug, 2021 Summarize Comments Improve Suggest changes Share Like Article Like Report A structure is a user-defined data type in C/C++. A structure creates a data type that can be used to group items of possibly different types into a single type. The ‘struct’ keyword is used to create a structure. The general syntax for creating a structure is as shown below: Syntax- struct structureName{ member1; member2; member3; . . . memberN; }; Structures in C++ can contain two types of members: Data Member- These members are normal C++ variables. A structure can be created with variables of different data types in C++.Member Functions- These members are normal C++ functions. Along with variables, the functions can also be included inside a structure declaration. Problem Statement: Why the size of an empty structure is not zero in C++ but zero in C. Solution:Below is the C program with an empty structure: C // C program with an empty // structure #include <stdio.h> // Driver code int main() { // Empty Structure struct empty { }; // Initializing the Variable // of Struct type struct empty empty_struct; // Printing the Size of Struct printf("Size of Empty Struct in C programming = %ld", sizeof(empty_struct)); } OutputSize of Empty Struct in C programming = 0 Below is the C++ program with an empty structure: C++ // C++ program to implement // an empty structure #include <iostream> using namespace std; // Driver code int main() { // Empty Struct struct empty { }; // Initializing the Variable // of Struct type struct empty empty_struct; // Printing the Size of Struct cout << "Size of Empty Struct in C++ Programming = " << sizeof(empty_struct); } OutputSize of Empty Struct in C++ Programming = 1 If observed carefully, the same code is executed in C and C++, but the output is different in both cases. Let's discuss the reason behind this- The C++ standard does not permit objects (or classes) of size 0. This is because that would make it possible for two distinct objects to have the same memory location. This is the reason behind the concept that even an empty class and structure must have a size of at least 1. It is known that the size of an empty class is not zero. Generally, it is 1 byte. The C++ Structures also follow the same principle as the C++ Classes follow, i.e. that structures in c++ will also not be of zero bytes. The minimum size must be one byte.Creating an empty structure in C/C++ is a syntactic constraint violation. However, GCC permits an empty structure in C as an extension. Furthermore, the behavior is undefined if the structure does not have any named members because: C99 says- If the struct-declaration-list contains no named members, the behavior is undefined. This implies- // Constraint Violation struct EmptyGeeksforGeeks {}; // Behavior undefined, // since there is no named member struct EmptyGeeksforGeeks {int :0 ;}; Comment More infoAdvertise with us Next Article Why is the Size of an Empty Class Not Zero in C++? C cheerssamyakjain Follow Improve Article Tags : C++ misc cpp-structure memory-management C-Structure & Union +1 More Practice Tags : CPPMisc Similar Reads Slack Bytes in Structures : Explained with Example Structures: Structures are used to store the data belonging to different data types under the same variable name. An example of a structure is as shown below: struct STUDENT { char[10] name; int id; }; The memory space for the above structure would be allocated as shown below: Here we see that there 3 min read Why is the Size of an Empty Class Not Zero in C++? When the structure was introduced in C, there was no concept of Objects at that time. So, according to the C standard, it was decided to keep the size of the empty structure to zero. In C++, the Size of an empty structure/class is one byte as to call a function at least empty structure/class should 4 min read Difference between Struct and Enum in C/C++ with Examples Structure in C++ A structure is a user-defined data type in C/C++. A structure creates a data type that can be used to group items of possibly different types into a single type. The âstructâ keyword is used to create a structure. Syntax: struct structureName{ member1; member2; member3; . . . member 3 min read Difference Between Structure and Class in C++ In C++, a structure works the same way as a class, except for just two small differences. The most important of them is hiding implementation details. A structure will by default not hide its implementation details from whoever uses it in code, while a class by default hides all its implementation d 3 min read Difference Between C Structures and C++ Structures Let's discuss, what are the differences between structures in C and structures in C++? In C++, structures are similar to classes. Differences Between the C and C++ StructuresC Structures C++ Structures Only data members are allowed, it cannot have member functions.Can hold both: member functions and 6 min read Difference between Structure and Array in C Array in C An array is collection of items stored at contiguous memory locations. Structure in C A structure is a user defined data type in C/C++. A structure creates a data type that can be used to group items of possibly different types into a single type. Difference between Structure and Array AR 2 min read Like