A static local persists; an automatic local restarts

Give the exact output and a table for both calls showing step, total before/after the update, calls before/after its increment and the returned value. Explain how a variable can be local in scope while living for the whole program.

    Predict the new output if static is removed from the declaration of total AND the declaration is changed to int total = 0;. Explain why simply removing static without adding that initializer would be a different and invalid way to obtain a clean per-call counter.

#include <stdio.h>
int record(int step)
{
    static int total;
    int calls = 0;
    total += step;
    ++calls;
    printf("inside total=%d calls=%d\n", total, calls);
    return total;
}
int main(void)
{
    int first = record(2);
    int second = record(3);
    printf("saved first=%d second=%d\n", first, second);
    return 0;
}

