Friday, 26 May 2017

Write a C program to find size of structure without using sizeof operator.

Q : Write a C program to find size of structure without using sizeof operator.

#include<stdio.h>

#include<conio.h>

struct stu

{

int roll;

char
name[20];

float
marks[3];

};

void main()

{

struct stu
*pt=NULL;

clrscr();

pt++;

printf("\n\tSize
of pointer is %d",pt);

getch();

}

NULL means pointer is not point any location. So NULL will
assign 0 in it. Increment operator jump
pointer some byte further which is equivalent to the size of pointer. This
process is same as in array for address calculation.