Skip to content
Home » Size of Structure data type

Size of Structure data type

Learn about Size of Structure data type in the below code example. Also refer the comments in the code snippet to get a detailed view about what’s actually happening.

Size of Structure data type

Structure (user defined data type) was introduced to store more than one primitive data type. In the preceding example, struct employee is a data type. In the same way that int is a data type, struct employee is a data type. It is important to note that struct or employee by themselves are not data types.

Program:

#include<stdio.h>
struct employee
{
   int number;
   char name[20];
   float salary;
};

int main()
{
   struct employee x;

   //Calculate size using variable name
   printf("Size of employee: %ld\n",sizeof(x));

   //Calculate size using data type
   printf("Size of employee: %ld\n",sizeof(struct employee));
   return 0;
}

Output:

Size of employee: 28
Size of employee: 28

Hope above code works for you and Refer the below Related Codes to gain more insights. Happy coding and come back again.

Similar Codes :
Size of a Variable
C Program to Find Size of Data Types