logo

Courses with this lesson

What is memory padding

#include <stdio.h> #include <stdlib.h> #include <string.h> #pragma pack(8) typedef struct Thing { int test; char k; char str[10]; int* p; short sh; } Thing; int main(int argc, char* argv[]) { int i; Thing t = { 12, 'k', "testing", &i, 256 }; printf("Size: %llu\n", sizeof(t)); unsigned char data; for (i = 0; i < sizeof(t); i++) { if (i % 8 == 0) { printf("\n"); } data = *(((unsigned char*) &t) + i); printf("%02x ", data); } return 0; }