78. Struct Padding

Back To All Submissions
Previous Submission
Next Submission

Code

#include <stdio.h>
#include <stddef.h>

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

int main() {
    struct MyStruct s;

    printf("Offset of a: %zu\n", offsetof(struct MyStruct, a));
    printf("Offset of b: %zu\n", offsetof(struct MyStruct, b));
    printf("Offset of c: %zu\n", offsetof(struct MyStruct, c));
    printf("Size: %zu\n", sizeof(struct MyStruct));

    return 0;
}

Solving Approach

 

 

 

Was this helpful?
Upvote
Downvote