Example 1 — Automatic versus static duration
The static counter remembers its value between calls.
#include <stdio.h>
void tick(void) {
int a = 0;
static int s = 0;
a++;
s++;
printf("auto=%d static=%d\n", a, s);
}
int main(void) {
tick();
tick();
tick();
return 0;
} How It Works
ais recreated and reset every call.sis initialized once and keeps its value.- Both have no linkage because they are local.
