Calculate Size of Structure
Size of Structure can be calculated as -

  1. By observation
  2. By Using sizeof Operator
  3. Without using Sizeof Operator
Way 1 : Calculate by adding Individual Sizes
struct Book
{
int pages;
char name[10];
char author[10];
float price;  
}b1;
Calculating Size of Structure :
= size of 'Pages' + size of 'Name' + size of 'Author' + size of 'Price'
= 2 + 10 * 1 + 10 * 1 + 4
= 2 + 10 + 10 + 4
= 26
Note :
  1. Add all the individual Size of Each Structure Member .
  2. Character array requires Memory Equivalent to  (No_of_elements * Sizeof(char))
  3. Float , Integer requires 4,2 bytes respectively in Case of Borland CC++ 3.0

Way 2 : Using Sizeof Operator
printf("Size of Structure : %d",sizeof(b1));
Way3 : Without Using Sizeof Operator : Click Here


Tags / Keywords : | , ,

0 comments

Post a Comment

Your Feedback :This is Growing Site and Your Feedback is important for Us to improve the Site performance & Quality of Content.Feel Free to contact and Please Provide Name & Contact Email