size of structure in c

Previous
Next

Size of structure:

  • Structure is a collection of elements.
  • The size is equals to sum of sizes of individual elements.
  • sizeof() function can be used to specify the size.

We can find the size either by using variable or data type

#include<stdio.h>
int main()
{
	int x ;	
	printf("int size : %d \n", sizeof(x));
	printf("int size : %d \n", sizeof(int));
	return 0;	
}

Finding Emp structure size:

#include<stdio.h>
struct Emp
{
	int no;
	char name[20];	
	float salary;
};
int main()
{
	struct Emp x ;	
	printf("Emp size : %d \n", sizeof(x));
	printf("Emp size : %d \n", sizeof(struct Emp));
	return 0;	
}
Previous
Next

Add Comment

Courses Enquiry Form