Pointer p to an array of integers (of size 2 Bytes) is initialised to 200. What is the value of p+3?
- (A)
206
- (B)
203
- (C)
212
- (D)
204
Pointer p to an array of integers (of size 2 Bytes) is initialised to 200. What is the value of p+3?
206
203
212
204
ANSWER
, which is option (A).
Official answer: ASource: ISRO's revised and final answer key of 16 February 2024
Pointer arithmetic scales by the size of the pointed-to type: moves the address by bytes.
Each integer element occupies bytes and .
So .
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