# **[](https://en.cppreference.com/w/c/header/stdalign)** provides `alignas()` and `alignof()` (C11) for memory alignment control. `alignof(type)` returns its alignment requirement; `alignas(N)` forces a variable or struct member to align to N bytes. Use it for SIMD operations, hardware register access, or matching binary layouts. ## Example This example demonstrates alignment queries and enforces 16-byte alignment. ```c // compile: gcc -std=c11 -o alignexample alignexample.c // run: ./alignexample // description: query and enforce memory alignment #include #include #include int main() { printf("alignof(char) = %zu\n", alignof(char)); printf("alignof(int) = %zu\n", alignof(int)); printf("alignof(double) = %zu\n", alignof(double)); alignas(16) float vec[4]; printf("vec[0] address mod 16 = %zu (should be 0)\n", (uintptr_t)vec % 16); return 0; } ``` ## Common macros **Alignment queries**: - `alignof(type)`: alignment requirement of type (in bytes) **Alignment enforcement**: - `alignas(N)`: align variable to N-byte boundary - `alignas(type)`: align variable same as type **Usage**: - `alignas(16) int x;`: align x to 16 bytes - `alignas(max_align_t) char buf[256];`: align to strictest requirement - `_Alignas(N)`: C11 keyword form (alignas is macro wrapper)