Return to course page

Quiz on second week's material.

Question 1: Given the following code, which options listed are valid type names?

typedef struct foo { int x; } baz;    

Select all that apply

  1. struct foo

  2. struct baz

  3. foo

  4. baz

Question 2: What does the following code print? (do not run the code: trace it by hand).

void main(void) {
    int i = 0, j = 0, k = 0;
    i = 1;
Start:
    goto L1;
L2:
    j = i+k;
    goto L3;
L1:
    k += 2;
    if (i < j) goto L3;
    goto L2;
L3:
    printf("%d %d %d\n", i, j, k);
}

Your answer should be either three numbers separated by spaces or the word ERROR if there is an error or it prints nothing.

Answer:

Question 3: In the C standard, what is the difference between "undefined behavior" and "implementation defined behavior"?

  1. an "implementation defined behavior" may vary between compilers, but not between programs created with the same compiler

  2. an "undefined behavior" may vary between compilers, but not between programs created with the same compiler

  3. they are synonyms

  4. none of the above

Question 4: Which of the following behave differently (result in different bits in their answers) when applied to signed vs. unsigned values?
Select all that apply

  1. <, >, etc

  2. <<

  3. >>

  4. binary operators + and -

  5. unary operator -

Question 5: If x and y are int values, what is the largest possible number of bits that could be set in z by the assignment z = (!x)&(~y);?

Answer:

Question 6: Which of the following are equivalent to !!x?
Select all that apply

  1. !~x

  2. ~!x

  3. -!x

  4. (-!x)&1

  5. (!x)&1

  6. 1 - (!x)

  7. (!x) - 1

Return to main page
Return to course page