C _Alignof Keyword
Example
Print the alignment of the char type:
printf("%zu", _Alignof(char));
Definition and Usage
The _Alignof keyword returns the alignment of a type, in bytes. The alignment tells where in memory a value of the type can start. For example, a type with alignment 4 always starts at a memory address that is a multiple of 4.
The result has the type size_t, so print it with %zu. The alignment of char is always 1. For other types, it depends on the system. For example, int often has alignment 4.
Write a type inside the parentheses, like _Alignof(int). If you include <stdalign.h>, you can write alignof instead of _Alignof.
Related Pages
The sizeof operator returns the size of a type, in bytes.
Read more about alignment in our C Struct Alignment and Padding Tutorial.