🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← Quiz: Searching and Sorting in C: all 10 questions

Quiz: Searching and Sorting in C · Question 7 of 10

What does this print? (code)

What does this print?

#include <stdio.h>
int main(void) {
    int a[] = {2, 5, 8, 12, 16, 23, 38};
    int low = 0, high = 6, steps = 0, key = 23;
    while (low <= high) {
        int mid = low + (high - low) / 2;
        steps++;
        if (a[mid] == key) break;
        if (a[mid] < key) low = mid + 1; else high = mid - 1;
    }
    printf("%d", steps);
    return 0;
}
  1. A.1
  2. B.2
  3. C.3
  4. D.6
Answer & explanation

Correct answer: 2

Step 1: mid = 3 (12) → go right. Step 2: mid = 5 (23) → found.

Can you get the rest right without peeking?

Take the timed Quiz: Searching and Sorting in C quiz free. Pass it to earn XP and count towards your certificate.

Start the quiz →