Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / C

alignof — type alignment requirement

The alignof operator queries a type's alignment requirement, not its size. _Alignof is an alternative spelling.

Version: C23; repository compiler flag, production runtime not attested

Syntax

alignof(type-name)
_Alignof(type-name)

alignof(T) returns the alignment requirement of type T in bytes as an integer constant expression of type size_t. Its value is implementation-defined; its operand is not evaluated.

In C23, alignof is a keyword requiring no header. _Alignof is an alternative spelling. Parentheses must contain a complete object type name, not an expression; void and function types are invalid.

For arrays, the result is the element type's alignment. sizeof measures size, whereas alignas specifies alignment for a declared object.

Examples

#include <stdio.h>

int main(void)
{
    printf("%d\n", alignof(int[3]) == alignof(int));
    return 0;
}

Result

1

The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.

Sources