typestar

Sized integer types in C

stdint.h gives you exact widths, which int and long do not promise.

#include <inttypes.h>
#include <stdint.h>
#include <stdio.h>

void widths(void) {
    int8_t small = -128;
    uint8_t byte = 255;
    int32_t medium = 2147483647;
    int64_t large = 9000000000LL;
    size_t count = sizeof(medium);

    printf("%d %u %d\n", small, byte, medium);
    printf("%" PRId64 " over %zu bytes\n", large, count);
}

How it works

  1. int32_t and uint8_t say exactly what they are.
  2. PRId64 is the printf specifier for an int64_t.
  3. size_t is the type for sizes and array indices.

Keywords and builtins used here

The run, in numbers

Lines
14
Characters to type
312
Tokens
75
Three-star pace
80 tpm

At the three-star pace of 80 tokens a minute, this run takes about 56 seconds.

Type this snippet

Step 4 of 7 in Variables & types, step 4 of 35 in Language basics.

← Previous Next →