typestar

Functions in C

Defining and composing functions, including static ones.

static int square(int x) {
    return x * x;
}

static int sum_of_squares(int a, int b) {
    return square(a) + square(b);
}

int hypotenuse_sq(int a, int b) {
    return sum_of_squares(a, b);
}

How it works

  1. static limits a function to this file.
  2. sum_of_squares calls square twice.
  3. The public function builds on the helpers.

Keywords and builtins used here

The run, in numbers

Lines
11
Characters to type
183
Tokens
56
Three-star pace
90 tpm

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

Type this snippet

Step 1 of 7 in Functions, step 15 of 35 in Language basics.

← Previous Next →

Functions in other languages