Why does empty Structure has size 1 byte in C++ but 0 byte in C Last Updated : 04 Aug, 2021 Comments Improve Suggest changes 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 does empty Structure has size 1 byte in C++ but 0 byte in C cheerssamyakjain Follow Improve Article Tags : C Language C++ misc cpp-structure memory-management C-Structure & Union +2 More Practice Tags : CPPMisc Similar Reads C Programming Language Tutorial C is a general-purpose mid-level programming language developed by Dennis M. Ritchie at Bell Laboratories in 1972. It was initially used for the development of UNIX operating system, but it later became popular for a wide range of applications. Today, C remains one of the top three most widely used 5 min read C++ Programming Language C++ is a computer programming language developed by Bjarne Stroustrup as an extension of the C language. It is known for is fast speed, low level memory management and is often taught as first programming language. It provides:Hands-on application of different programming concepts.Similar syntax to 5 min read Object Oriented Programming in C++ Object Oriented Programming - As the name suggests uses objects in programming. Object-oriented programming aims to implement real-world entities like inheritance, hiding, polymorphism, etc. in programming. The main aim of OOP is to bind together the data and the functions that operate on them so th 5 min read Inheritance in C++ The capability of a class to derive properties and characteristics from another class is called Inheritance. Inheritance is one of the most important features of Object-Oriented Programming in C++. In this article, we will learn about inheritance in C++, its modes and types along with the informatio 10 min read Dynamic Memory Allocation in C using malloc(), calloc(), free() and realloc() In C, a variable defined in a function is stored in the stack memory. The requirement of this memory is that it needs to know the size of the data to memory at compile time (before the program runs). Also, once defined, we can neither change the size nor completely delete the memory.To resolve this, 9 min read 30 OOPs Interview Questions and Answers [2025 Updated] Object-oriented programming, or OOPs, is a programming paradigm that implements the concept of objects in the program. It aims to provide an easier solution to real-world problems by implementing real-world entities such as inheritance, abstraction, polymorphism, etc. in programming. OOPs concept is 15 min read Vector in C++ STL C++ vector is a dynamic array that stores collection of elements same type in contiguous memory. It has the ability to resize itself automatically when an element is inserted or deleted.Create a VectorBefore creating a vector, we must know that a vector is defined as the std::vector class template i 7 min read Data Types in C Each variable in C has an associated data type. It specifies the type of data that the variable can store like integer, character, floating, double, etc.Example:C++int number;The above statement declares a variable with name number that can store integer values.C is a statically type language where 5 min read C Language Introduction C is a general-purpose procedural programming language initially developed by Dennis Ritchie in 1972 at Bell Laboratories of AT&T Labs. It was mainly created as a system programming language to write the UNIX operating system.Main features of CWhy Learn C?C is considered mother of all programmin 6 min read Page Replacement Algorithms in Operating Systems In an operating system that uses paging for memory management, a page replacement algorithm is needed to decide which page needs to be replaced when a new page comes in. Page replacement becomes necessary when a page fault occurs and no free page frames are in memory. in this article, we will discus 7 min read Like