Question:medium

The value printed by the given C program is __________ (Answer in integer).

Show Hint

To trace recursive functions, break down each recursive call step by step and evaluate the base cases and recursive conditions. This helps in understanding how the function processes the data.
Updated On: Jan 30, 2026
Show Solution

Correct Answer: 5

Solution and Explanation

The function processes the array by comparing each element with the next one. It increases its count whenever a change in value occurs between consecutive elements, and finally accounts for the last remaining element.

Hence, the value returned by the function corresponds to the number of contiguous blocks of equal values in the considered portion of the array.

For the array:

\(0, 1, 2, 2, 2, 2, 0, 0, 1\)

The distinct consecutive groups are:

  • \(0\)
  • \(1\)
  • \(2\)
  • \(0\)
  • \(1\)

There are exactly five such groups.

Therefore, the value printed by the program is \(\boxed{5}\).

Was this answer helpful?
0