About Me

My photo
Raipur, Chhattisgarh, India
Hi , I am Amit Thakur. I have worked as a QA Engineer for two years and as a Java Developer for one year in NIHILENT TECHNOLOGIES PVT. LTD., Pune.Currently I am working as DEAN (Research & Development) in Bhilai Institute of Technology, Raipur.

Wednesday, September 4, 2013

C Program to Calculate Size of Structure using Sizeof Operator

#include<stdio.h>
#include<conio.h>
struct stud
{
int roll;
char name[10];
int marks;
};

void main()
{
int size;
struct stud s;
clrscr();
size = sizeof(s);
printf("\nSize of Structure : %d",size);
getch();
}

Explanation :

  1. Structure is Collection of elements of the Different data Types.
  2. Size of the Structure Can be Evaluated using “sizeof Operator”
size = sizeof(s);

Formula for Calculating Size of Structure :

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.

No comments: