5/21/2023 #1 Modern C : getting started

A basic program

// getting-started.c
#include <stdlib.h>
#include <stdio.h>

int main(void) {
  double A[5] = {
    [0] = 9.0,
    [1] = 2.9,
    [4] = 3.E+25,
    [3] = .00007,
  };

  for (size_t i = 0; i < 5; ++i) {
    printf(
      "element %zu is %g, \tits square is %g\n",
      i,
      A[i],
      A[i] * A[i]
    );
  }
}

Compile

gcc -std=c17 -Wall -lm -o getting-started getting-started.c

Execute

./getting-started

This basic program prints :

element 0 is 9,         its square is 81
element 1 is 2.9,       its square is 8.41
element 2 is 0,         its square is 0
element 3 is 7e-05,     its square is 4.9e-09
element 4 is 3e+25,     its square is 9e+50

Acknowledgments

The source of this memo is from the 'Modern C' book, by Jens Gustedt, Manning 2020.