#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
Upvote
Downvote
Loading...
Input
Expected Output
Offset of a: 0
Offset of b: 4
Offset of c: 8
Size: 12