All submissions

Code

#include <stdio.h>
#include<stdint.h>
typedef struct {
    char a;
    int b;
    short c;
} MyStruct;

void print_offsets() {
    MyStruct s;
    uint8_t *ps, *pa, *pb, *pc;
    ps = (uint8_t*) &s;
    pa = (uint8_t*) &s.a;
    pb = (uint8_t*) &s.b;
    pc = (uint8_t*) &s.c;

    printf("Offset of a: %u\n",(pa-ps));
    printf("Offset of b: %u\n",(pb-ps));
    printf("Offset of c: %u\n",(pc-ps));
    printf("Size: %d",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