Bird
0
0

What is the output of this C function?

medium📝 Predict Output Q13 of 15
C - Loop Control Statements
What is the output of this C function?
int findFirstEven(int arr[], int size) {
  for(int i = 0; i < size; i++) {
    if(arr[i] % 2 == 0) {
      return arr[i];
    }
  }
  return -1;
}

int main() {
  int nums[] = {3, 7, 8, 5};
  printf("%d", findFirstEven(nums, 4));
  return 0;
}
A3
B7
C8
D-1
Step-by-Step Solution
Solution:
  1. Step 1: Trace the loop to find first even number

    The array is {3, 7, 8, 5}. Loop checks each element: 3 (odd), 7 (odd), 8 (even).
  2. Step 2: Return when first even found

    At element 8, condition is true, so function returns 8 immediately, skipping rest.
  3. Final Answer:

    8 -> Option C
  4. Quick Check:

    Return stops loop at first even number 8 [OK]
Quick Trick: Return inside loop returns first matching value [OK]
Common Mistakes:
  • Assuming loop continues after return
  • Returning wrong element index
  • Confusing return value with loop index

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More C Quizzes