Code

#include <stdio.h>

typedef struct {
    char a;
    int b;
    short c;
} MyStruct;

void print_offsets() {
    MyStruct ms;
    ms.a = 0;
    ms.b = 4;
    ms.c = 8;

    int size = (int)ms.a + ms.b + (int)ms.c;

    printf("Offset of a: %d\n", ms.a);
    printf("Offset of b: %d\n", ms.b);
    printf("Offset of c: %d\n", ms.c);
    printf("Size: %d\n", size);
 
}

int main() {
    print_offsets();
    return 0;
}

Solving Approach

 

 

 

Upvote
Downvote
Loading...

Input

Expected Output

Offset of a: 0 Offset of b: 4 Offset of c: 8 Size: 12