typestar

Variables and printf in C

Declaring typed variables and printing them.

void describe(void) {
    int count = 42;
    double ratio = 3.5;
    char grade = 'A';
    const char *name = "typestar";

    printf("%s: %d items, %.1f ratio, grade %c\n",
           name, count, ratio, grade);
}

How it works

  1. Each variable has an explicit type: int, double, char.
  2. A const char * points at a string literal.
  3. printf interpolates with %d, %.1f, %c, %s.

Keywords and builtins used here

The run, in numbers

Lines
9
Characters to type
184
Tokens
49
Three-star pace
80 tpm

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

Type this snippet

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

Next →