Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / C

unsigned long — unsigned integer type

unsigned long stores nonnegative integers. ULONG_MAX specifies its maximum value; its width is not fixed.

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

Syntax

unsigned long name = 0UL;

unsigned long and unsigned long int name the same type. Its range is 0 through ULONG_MAX from <limits.h>, with ULONG_MAX at least 4294967295. Do not assume a 64-bit width.

Arithmetic in this type works modulo the mathematical value ULONG_MAX + 1: adding 1UL to the maximum gives 0. This is not undefined behavior, but may indicate a calculation error.

The UL suffix denotes an unsigned long constant if the value fits. Use %lu with printf. The example demonstrates wrapping independently of the type's width.

Examples

#include <limits.h>
#include <stdio.h>

int main(void)
{
    unsigned long value = ULONG_MAX;
    value += 1UL;
    printf("%lu\n", value);
    return 0;
}

Result

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