Multiple choice

/* Increment each integer in the array 'p' of * size 'n'. / void increment_ints (int p [/*n/], int n) { assert(p != NULL); /* Ensure that 'p' isn't a null pointer. / assert(n >= 0); / Ensure that 'n' is nonnegative. / while (n) / Loop over 'n' elements of 'p'. / { *p++; / Increment p. */ p++, n--; / Increment p, decrement n. */ } }

Consider the function increment_ints(), defined above. Despite its significant inline commentary, it contains an error. Which one of the following correctly assesses it?

  1. *p++ causes p to be incremented before the reference is performed because both operators have equal precedence and are right associative.

  2. An array is a non-modifiable value, so p cannot be incremented directly. A navigation pointer should be used in conjunction with p.

  3. *p++ causes p to be incremented before the dereference is performed, because the auto-increment operator has higher precedence than the indirection operator.

  4. The condition of a while loop must be a Boolean expression. The condition should be n != 0.

  5. An array cannot be initialized to a variable size. The subscript n should be removed from the definition of the parameter p.

Reveal answer Fill a bubble to check yourself
E Correct answer