Padding for Struct Members

Learn more about how structures are represented in memory.

Introduction

Let’s revisit a previous example for a structure definition.

typedef struct
{
	char x;
	int y;
} TExample;

Assume the following declaration:

TExample p;

When representing it in memory, we may assume the following layout:

  • x starts at the beginning of p.
  • x is 1 byte long.
  • y starts 1 byte after x.

Get hands-on with 1200+ tech skills courses.