First Steps with C11

Content

Some remarks on compiling C code:

For all examples do the following:

Example on Arrays

#define N   5

unsigned char x[N] = {1,2,3,4,5};

int main()
{
    register unsigned long long  res = 0;
    for (register unsigned long long i=0; i<N; ++i) {
        res += x[i];
    }
    return res;
}

Example on For loops

#define N   5

int main()
{
    register unsigned long long  res = 1;
    for (register unsigned long long i=2; i<=N; ++i) {
        res *= i;
    }
    return res;
}

Example on While loops

Explain why the following program will not compile. Then fix it and proceed as before:

#define N   5

int main()
{
    register unsigned long long  res = 1;
    while (N>1) {
        res *= N;
        --N;
    }
    return res;
}