Thursday, December 22, 2011

Finding sizeof structure without using sizeof operator


//FIND OUT THE SIZE OF STRUCTURE WITHOUT USING sizeof OPERATOR
#include<stdio.h>

struct str
{
  int a;
  char d;
  int c;
};


int main()
{
  struct str a, b;
  struct str *pt, *qt;
  int size;

  pt = &a;
  qt = &b;

  size = (void*)pt-(void*)qt;

  printf("Size of struct = %d\n", size);

  return 0;
}

No comments:

Post a Comment