#include <stdio.h> #include <stdint.h> typedef struct { char a; int b; short c; } MyStruct; void print_offsets() { MyStruct rekord; uint8_t * p0 = (uint8_t *)(&rekord); uint8_t * p1 = (uint8_t *)(&(rekord.a)); uint8_t * p2 = (uint8_t *)(&(rekord.b)); uint8_t * p3 = (uint8_t *)(&(rekord.c)); uint8_t total = sizeof(rekord); //print values printf("Offset of a: %u\n", p1 -p0); printf("Offset of b: %u\n", p2 -p0); printf("Offset of c: %u\n", p3 -p0); printf("Size: %u\n", total); } int main() { print_offsets(); return 0; }
Test Cases
Test Results
Input
Expected Output
Offset of a: 0 Offset of b: 4 Offset of c: 8 Size: 12