Interviews Questions, Algorithms, Aptitude, C Interview Program, C Theory Question, Aptitude Tricks, Test Series,

Tuesday, 14 May 2019

The Interview Question Today#27(26-3-19)(Size of structure)

Question:

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

Solution:

C program:

#include<stdio.h>
struct  XYZ{
    int x;
    float y;
    char z;
};

int main(){
    int sz = (int) (((struct XYZ *)0) + 1);
    printf("Size of Struct= %d",sz);
    return 0;

}


Output:

Size of Struct= 12

0 comments:

Post a Comment