C - Find the size of structure

后端 未结 7 987
再見小時候
再見小時候 2021-02-10 01:43

I was asked this as interview question. Couldn\'t answer.

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

7条回答
  •  灰色年华
    2021-02-10 01:53

    struct  XYZ{
        int x;
        float y;
        char z;
    };
    
    int main(){
        struct XYZ arr[2];
        int sz = (char*)&arr[1] - (char*)&arr[0];
        printf("%d",sz);
        return 0;
    }
    

提交回复
热议问题