1. Home
  2. Computer Science MCQs
  3. C Programming
  4. With int (*p)[5] and 4-byte ints, by how many bytes does p…

Added 30 Nov -0001

With int (*p)[5] and 4-byte ints, by how many bytes does p + 1 advance?

  1. 5
  2. 8
  3. 20 Correct answer
  4. 4

Correct answer

C. 20

17 views

MCQSEXAM

Explanation

Pointer arithmetic scales by the size of the pointed-to type, and here that type is int[5], which occupies 20 bytes. This is why a pointer to an array steps one whole row at a time in two-dimensional arrays. By contrast int *q[5] declares an array of five pointers, and q + 1 there would move by one pointer only.

Reference

Asked in: NTS, PPSC IT, Campus Interviews

Preparing for an exam?

Doubts & discussion

Not sure why the answer is C? Ask here and get an explanation.

Ask a doubt about this MCQ

Shown after review. No links please.

More C Programming MCQs

Practise all C Programming MCQs

Similar MCQs