Multiple choice

Assume the following declarations in C++ int num [5] = {3, 4, 6, 2, 1} ; int *p = num;

Which of the following is correct?

  1. num[1] is same as p+1

  2. num[2] is same as &(p+2)

  3. num[3] is same as *(p+3)

  4. num is same as *p

Reveal answer Fill a bubble to check yourself
C Correct answer
Explanation

When p = num, p points to the first element. Array indexing num[i] is equivalent to *(num + i) or *(p + i). Option A is wrong because p+1 is an address, not a value. Option B is syntactically invalid - &(p+2) doesn't make sense. Option C is correct: num[3] = *(p+3) dereferences the pointer to get the value. Option D is wrong: *p gives the first element's value (3), not the array itself.