Pages

Friday, December 28, 2012

Size of Structure - C Programming

To find out the size of structure by sizeof operator,we can either use the structure variable name or the tagname with the  struct keyword. For Example -::


sizeof(struct student)
sizeof(stu1) // Here stu1 is variable structure type



struct student {
   char name[20]; //Occupy 1 * 20 = 20 bytes
   int rollno;       //4 bytes
};
struct student stu1;

printf("size of structure  is %d\n",sizeof(struct student));
printf("size of structure is %d\n",sizeof(stu1));


Output ::
 24
 24

Size of datatype depend on compiler


No comments:

Post a Comment