CS202: HW 1: C review, processes

CS202: HW 1: C review, processes

These problems should be done on your own. We're not going to be grading them strictly (we'll mainly look at whether you attempted them). But they will be reinforcing knowledge and skills, so you should totally work through them carefully.

Problem 1:

This is a brief C exercise. (The labs will require comfort and fluency in C.) Below is a snippet of code:

void op1(int a, int b) {
    a = a + b;
}

void op2(int* a, int* b) {
    *a = *a + *b;
}

int main() {
    int a = 1, b = 1, c = 1, d = 1;
    op1(a, b);
    op2(&c, &d);
    return 0;
}

What are the values of a, b, c, and d right before the program exits? Since the purpose of this exercise is to build your skills, you should do this problem without compiling and running the program.

Problem 2:

Below is another snippet of C code:

int a[5];

a[0] = 0;
a[1] = 10; 
a[2] = 100;

//COMMENT 1

a[3] = *a + 2;
a[4] = *(a + 2); 

//COMMENT 2

What are the values stored in the array a when the program reaches COMMENT 1? (Do we know all of the values?) What about when the program reaches COMMENT 2?

Problem 3:

Operations on files, such as read(), write(), and close(), are typically implemented as system calls. Describe two of the benefits of having these operations managed by the operating system instead of individual processes.

Handing in the homework

Use Gradescope; you can enroll in our course with entry code JBGJKG. (And please feel free to send us feedback about Gradescope.)