Wednesday 27 March 2013

Write a c program to find size of structure without using sizeof operator?


Write a c program to find size of structure without using sizeof operator? 

Explanation:
struct  ABC{
    int a;
    float b;
    char c;
};
int main(){
    struct ABC *ptr=(struct ABC *)0;
    ptr++;
    printf("Size of structure is: %d",ptr);
    return 0;
}


Example 2:

#include <stdio.h>
#include <conio.h>

struct  ABC{
    int a;
    char c;
};
void main(){
clrscr();
struct ABC*temp;
printf("%d",(char*)(temp+1)-(char*)temp);
getch();
}

Blog Author: Vijay Kumar

No comments:

Post a Comment