C Program to Calculate Size of Structure using Sizeof Operator
Program : Calculate Size of Structure in C Programming
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | #include<stdio.h> struct stud { int roll; char name[10]; int marks; }; int main() { int size; struct stud s; size = sizeof(s); printf("nSize of Structure : %d", size); return(0); } |
Explanation :
- Structure is Collection of elements of the Different data Types.
- Size of the Structure Can be Evaluated using “sizeof Operator”
1 | size = sizeof(s); |
Formula for Calculating Size of Structure :
1 2 3 | Size of Structure 'S' = sizeof(roll) + sizeof(name) + sizeof(mark) = 2 + 10 + 2 = 14 |
Remember :
- Sizeof is Operator not function
- Sizeof Operator Takes any Variable as Parameter.