UC3M

Telematic/Audiovisual Syst./Communication Syst. Engineering

Systems Architecture

September 2017 - January 2018

1.3.  Activities

1.3.1.  The elements of a C program

Resources

A resource that is worth keeping it handy to check (not to read right now because it has 300 pages) is The GNU C Programming Tutorial written by Mark Burgess (Online version). It contains detail information about everything related to C.

Work Plan

After reading the suggested document, answer to the questions in the following section.

Assessment

Remember that when the compiler processes source files, it does so independently and in a single pass. Consider the following source files.

file_1.c file_2.c file_3.c
1
2
3
4
5
6
7
8
9
10
int b = 10;

void fill_squares(int *tbl, int b) 
{
    int i;
    for (i = 0; i < b; i++) 
    {
        tbl[i] = square(i + 1);
    }
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#define SIZE 10

int cube(int);

int main(int argc, char *argv[]) 
{
    int a;
    int table[SIZE];

    a = square(b);
    b = cube(a);

    fill_squares(table, SIZE);
    return 0;
}

int square(int number) 
{
    return number * number;
}
1
2
3
4
5
6
int b = 10;

int cube(int number) 
{
  return square(number) * number;
}

Answer the following questions.

  1. In file_1.c the parameter b (line 3) and the global variable b (line 1) are different variables.

    • True

    • False

  2. In line 8 of file_1.c the compiler does not know function square. A prototype needs to be included before the function to avoid a warning by the compiler.

    • True

    • False

  3. In line 10 of file_2.c the compiler knows nothing about function square.

    • True

    • False

  4. In line 11 of file_2.c the compiler knows nothing about function cube.

    • True

    • False

  5. The assignment to b in line 11 of file_2.c is correct because it is a global variable defined in another file.

    • True

    • False

  6. Function square in line 17 of file_2.c needs to be moved to the beginning of the file (or at least its prototype) for the compiler not to emit a warning.

    • True

    • False

  7. The declaration of b in line 1 of file_3.c is incorrect because it collides with the declaration in line 1 of file_1.c.

    • True

    • False

  8. The compiler has no information about function square in line 5 of file_3.c.

    • True

    • False

Post in the course forum or check with the professors those questions that you are not sure about the answer.