src/hello.c @ ac2585e ↗
1/* hello.c: the smallest program worth teaching.
2 It adds two numbers and prints the total. */
3#include <stdio.h>
4
5static int add(int a, int b)
6{
7 return a + b;
8}
9
10int main(void)
11{
12 int total = add(2, 3);
13 printf("%d\n", total);
14 return 0;
15}

Introduction

Adding two numbers

This tiny program has two functions. The helper takes two integers and returns their sum. The entry point calls it once and prints the result.

flow main main() add add(a, b) main->add out printf main->out add->main
Call flow

Real SIMD code would replace the single addition with something like _mm256_fmadd_ps, which is why every kernel lesson links intrinsic names to the vendor's reference.

Knowledge check

1. What does add(2, 3) return?
2. Which function is the program's entry point?
  1. This program adds two numbers. The helper function takes two integers.
  2. It returns their sum on a single line.
  3. The entry point calls the helper once, then prints the total.