Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / C

alignof — a type's alignment requirement

The C23 alignof operator reports a type's alignment requirement in bytes, not an object's size.

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

Syntax

alignof(type-name)

alignof(type-name) yields an integer constant expression of type size_t. Its value is implementation-defined. The operand is not evaluated.

Parentheses and a type name are required; an ordinary expression is not allowed. Function types and incomplete types, including void, are forbidden. For arrays, the result is the element type's alignment requirement.

In C23, alignof is a keyword requiring no header. _Alignof is the older, deprecated spelling. sizeof measures size. An object declaration can use alignas to request stricter alignment than the object's type requires. alignof reports the named type's alignment requirement, not any stricter alignment requested for a particular 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