ProgrammingHardCompetitive coding (CP) · C internals

What is the output of this C program (assume a typical 64-bit platform: int 32 bits, long and pointers 64 bits, double 8 bytes, structs aligned to their widest member with no packing pragma)? #include <stdio.h> int findIndex(int *a, int n, int target) { for (int i = 0; i < n; i++) if (a[i] == target) return i; return -1; } int main(void) { int arr[6] = {4, 8, 15, 16, 23, 42}; printf("%d %d", findIndex(arr, 6, 16), findIndex(arr, 6, 99)); return 0; }

  1. A. 3 -1
  2. B. 4 0
  3. C. 4 -1
  4. D. 3 0

Correct answer: A. 3 -1

16 sits at index 3 (0-indexed) in the array; 99 is not present, so the function returns the sentinel -1.

More C Programming questions

Exams that ask this topic