1. Home
  2. Computer Science MCQs
  3. C Programming
  4. The prototype void f(int a[static 10]) makes what promise…

Added 30 Nov -0001

The prototype void f(int a[static 10]) makes what promise to the compiler and to the caller?

  1. a is a local copy of ten elements, so writes inside f do not escape
  2. a may be a null pointer whenever fewer than ten elements are supplied here
  3. a points to at least 10 elements, allowing more aggressive code generation Correct answer
  4. a must hold exactly ten elements, and longer arrays are not permitted

Correct answer

C. a points to at least 10 elements, allowing more aggressive code generation

20 views

MCQSEXAM

Explanation

The static array parameter form is a contract: the pointer supplied must address at least the stated number of elements, which lets the compiler assume non-null and unroll or prefetch accordingly. It does not copy the array, and it does not forbid a longer array. Passing fewer than ten elements, or a null pointer, makes the call undefined behaviour even though no diagnostic is required.

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