All submissions

Code

#include <stdio.h>

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

void print_offsets() {
    MyStruct s;
    int a_off =  (long)((char*)(&(s.a))) - (long)((char*)(&s));
    int b_off =  (long)((char*)(&(s.b))) - (long)((char*)(&s));
    int c_off =  (long)((char*)(&(s.c))) - (long)((char*)(&s));
    printf("Offset of a: %ld\n", a_off);
    printf("Offset of b: %ld\n", b_off);
    printf("Offset of c: %ld\n", c_off);
    printf("Size: %u", sizeof(s));
}

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