Bird
0
0

What will be printed by this C program?

medium📝 Predict Output Q5 of 15
C - Loop Control Statements
What will be printed by this C program?
int findFirstNegative(int arr[], int size) {
  for(int i = 0; i < size; i++) {
    if(arr[i] < 0) return i;
  }
  return -1;
}

int main() {
  int nums[] = {4, 7, 0, -3, 5};
  printf("%d", findFirstNegative(nums, 5));
  return 0;
}
A4
B0
C-1
D3
Step-by-Step Solution
Solution:
  1. Step 1: Check array elements one by one

    Elements are 4, 7, 0, -3, 5. The first negative is -3 at index 3.
  2. Step 2: Return index when negative found

    Function returns index 3 immediately when arr[3] < 0.
  3. Final Answer:

    3 -> Option D
  4. Quick Check:

    Return inside loop returns first negative index [OK]
Quick Trick: Return inside loop returns first found condition index [OK]
Common Mistakes:
  • Returning index 0 by mistake
  • Returning -1 even when negative exists
  • Confusing array values with indexes

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More C Quizzes