IAE Academy

ISRO CS 2023 Q.27: solution and answer

ISRO 2023 · CSQ.27 · 1 mark · MCQ

Pointer p to an array of integers (of size 2 Bytes) is initialised to 200. What is the value of p+3?

  1. (A)

    206

  2. (B)

    203

  3. (C)

    212

  4. (D)

    204

See the question in the paper

Answer and solution

ANSWER

, which is option (A).

Official answer: ASource: ISRO's revised and final answer key of 16 February 2024

  1. Pointer arithmetic scales by the size of the pointed-to type: moves the address by bytes.

  2. Each integer element occupies bytes and .

  3. So .

  4. Option (b) adds bytes and ignores the scaling. Option (c) would need a -byte element, since . Option (d) equals , which is an off-by-one in the element count.

KEY IDEA

Adding to a pointer advances it by elements, so the address changes by (element type) bytes.

WATCH OUT FOR

Adding to the address directly, which gives . This forgets that pointer arithmetic is scaled by the element size.

From the ISRO CS 2023 paper. Every question of this paper · The full paper (PDF, ISRO) · All 2 ISRO Pointers & arrays questions, with notes