78. Struct Padding

Back To All Submissions
Previous Submission
Next Submission

Code

#include <stdio.h>
#include <stddef.h>   // for offsetof

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

int main(void)
{
    struct Example s;

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

    return 0;
}

Solving Approach

 

 

 

Was this helpful?
Upvote
Downvote