All submissions

Code

#include <stdio.h>

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

void print_offsets() {
    MyStruct s;

   char *ptr_s = (char*)&s;
   char* ptr_a = (char*)&s.a;
   char* ptr_b =(char*)&s.b;
   char* ptr_c =(char*)&s.c;


    printf("Offset of a: %ld",ptr_a - ptr_s);
    printf("\nOffset of b: %ld",ptr_b - ptr_s);
    printf("\nOffset of c: %ld",ptr_c - ptr_s);
    printf("\nSize: %zu",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