The prototype void f(int a[static 10]) makes what promise to the compiler and to the caller?
Correct answer
C. a points to at least 10 elements, allowing more aggressive code generation
20 views
C. a points to at least 10 elements, allowing more aggressive code generation
20 views
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.
Asked in: NTS, PPSC IT, Campus Interviews
Not sure why the answer is C? Ask here and get an explanation.