1. Home
  2. Computer Science MCQs
  3. C Programming
  4. What does the restrict qualifier on a pointer parameter…

Added 30 Nov -0001

What does the restrict qualifier on a pointer parameter promise the compiler?

  1. That the object it points to is accessed only through that pointer and pointers derived from it within the block Correct answer
  2. That the pointer is never null and always points to a valid object for the whole duration of the call
  3. That the pointed-to object is read-only for the duration of the call, so the compiler may cache its value in registers
  4. That the pointer variable itself cannot be reassigned inside the function, although the pointee may change

Correct answer

A. That the object it points to is accessed only through that pointer and pointers derived from it within the block

18 views

MCQSEXAM

Explanation

restrict is an aliasing promise: if the object is modified through another independent pointer during the block, behaviour is undefined, which lets the compiler reorder and vectorise loads and stores. It is used in memcpy to justify assuming source and destination do not overlap, unlike memmove. It says nothing about nullness or constness, which are separate qualifiers and contracts.

Reference

Asked in: NTS, PPSC IT, Campus Interviews

Preparing for an exam?

Doubts & discussion

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