Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / C

Less-than operator (<)

The < operator tests strict ordering. Its int result is 1 when the comparison is true and 0 otherwise.

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

Syntax

left < right

left < right tests whether the left operand is smaller; equality yields 0.

Numeric operands require real types; usual arithmetic conversions precede comparison. Beware: -1 < 1u yields 0 through conversion to unsigned int.

Do not express ranges as a < b < c: this means (a < b) < c. Use a < b && b < c.

Pointers must target compatible, optionally qualified object types. Ordering within one array, including its one-past position, is defined; comparing pointers to unrelated objects has undefined behavior.

Examples

#include <stdio.h>

int main(void)
{
    int a = 3;
    int b = 5;
    printf("%d %d %d\n", a < b, b < a, a < a);
    return 0;
}

Result

1 0 0

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