1. Home
  2. Computer Science MCQs
  3. C Programming
  4. If int *p holds address 1000 and int is 4 bytes, what does…

Added 30 Nov -0001

If int *p holds address 1000 and int is 4 bytes, what does p++ leave in p?

  1. 1004, only if p points to an array
  2. 1004, one int further along in memory Correct answer
  3. 1001, one byte further along in memory
  4. 1000, since the address is unchanged

Correct answer

B. 1004, one int further along in memory

13 views

MCQSEXAM

Explanation

Incrementing a pointer advances it by sizeof(*p) bytes, not by one byte, so an int pointer moves 4 bytes and lands on 1004. This scaling is exactly what makes indexing work, since p + i must reach the i-th element rather than the i-th byte. The behaviour is defined only while the result stays inside the same array or one past its end.

Reference

Asked in: NTS, PPSC IT, Campus Interviews

Preparing for an exam?

Doubts & discussion

Not sure why the answer is B? 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