Home » C programming language

Size of structure with no members in C programming language



Learn: can we declare a structure with no members, if yes what will be the size of that structure? In this article we are going to learn about size of structure with no members (or Empty Structure) in C language with an example.

Yes, it is allowed in C programming language that we can declare a structure without any member and in that case the size of the structure with no members will be 0 (Zero). It will be a Zero size structure.

The GNU C Reference Manual says:
"As a GNU extension, GCC allows structures with no members. Such structures have zero size."

Consider the program:

In this C program, we are declaring a structure named "temp" without declare any variable in it, so "temp" is a structure with no members.

Then, we are declaring its variable "T" (Structure variable) and printing occupied size by "T" using sizeof() operator, and the result is "0".

#include <stdio.h>

//structure with no members
struct temp
{
    
};


int main()
{
    //declaring stcurure variable
    struct temp T;
    
    printf("Size of T: %d\n",sizeof(T));

    return 0;
}

Output

Size of T: 0





Was this page helpful? YES NO

Are you a blogger? Join our Blogging forum.



Comments and Discussions


We are using Google to publish ads on our website; Google has its own privacy policies. They may save log, cookies on your system. Google may also collect information of your system like IP address, region, city, country. For more details please go through the Google’s privacy policy.