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

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