All submissions

Code

#include <stdio.h>

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

void print_offsets() {
    MyStruct m;
     printf("Offset of a: %lu\n", ((char*)(&m.a)-(char*)(&m)));
     printf("Offset of b: %lu\n", ((char*)(&m.b)-(char*)(&m)));
     printf("Offset of c: %lu\n", ((char*)(&m.c)-(char*)(&m)));
     printf("Size: %lu",sizeof(m));
     

}

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

Solving Approach

 

 

 

Loading...

Input

Expected Output

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