Structure Types and Memory Alignment in C Language
Structure Definition
Defining Structure Types
The syntax for defining a structure type is:
struct StructName {
// member variables
int member1;
float member2;
char member3;
};
Declaring Structure Variables
Declaring during definition:
struct Point {
int x;
int y;
} p1, p2; // declares two Point variables
Separate decla ...
Posted on Wed, 08 Jul 2026 17:12:58 +0000 by cocpg
Understanding Structures, Enums, and Unions in C Programming
Structure Declaration
Basic Concepts
Structures group values of different types under a single name. Each value is called a member variable.
Declaration Syntax
struct tag {
member_list;
} variable_list;
Example: A student structure with name, age, gender, and height:
struct Student {
char name[20];
int age;
char gender[2];
...
Posted on Sun, 28 Jun 2026 17:11:42 +0000 by russy
Understanding Memory Alignment and Padding in C Structs
Calculating Member Offsets
To understand how structures are laid out in memory, it is useful to know the concept of an offset. The offset of a member is the distance in bytes from the start of the structure's base address. The first member always has an offset of 0.
You can utilize the standard macro offsetof (defined in stddef.h) to inspect th ...
Posted on Fri, 08 May 2026 22:44:06 +0000 by rathersurf