Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / C

typeof — type specifier

In C23, typeof lets a declaration use the type of an expression or a type name while preserving qualifiers.

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

Syntax

typeof(expression)
typeof(type-name)

typeof in C23 is a type specifier, not a value-returning function. It accepts an expression or a type name; no header is required.

It preserves qualifiers, including const and _Atomic. By contrast, typeof_unqual yields the non-atomic, top-level-unqualified type. The operand must not designate a bit-field.

The operand is evaluated if it has variably modified type; otherwise, it is not evaluated. In the example, count++ does not increment count: next has type int, and limit has type const int. Check C23 support in the target compiler.

Examples

#include <stdio.h>

int main(void)
{
    int count = 3;
    typeof(count++) next = 7;
    typeof(const int) limit = 10;

    printf("%d %d %d\n", count, next, limit);
    return 0;
}

Result

3 7 10

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