VOOZH about

URL: https://www.geeksforgeeks.org/cpp/why-does-empty-structure-has-size-1-byte-in-c-but-0-byte-in-c/

⇱ Why does empty Structure has size 1 byte in C++ but 0 byte in C - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Why does empty Structure has size 1 byte in C++ but 0 byte in C

Last Updated : 11 Feb, 2026

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.

  • C++ does not allow objects of size 0, because different objects must have distinct memory addresses.
  • Therefore, even an empty class or structure in C++ occupies at least 1 byte of memory.
  • This rule ensures that every object can be uniquely identified in memory.
  • In C, empty structures are not standard, though some compilers (like GCC) allow them as an extension, with undefined behavior.

Note: C99 says- If the struct-declaration-list contains no named members, the behavior is undefined. 

C program with an empty structure:


Output
Size of Empty Struct in C programming = 0

C++ program with an empty structure:


Output
Size of Empty Struct in C++ Programming = 1
Comment