The function foo(S, size) recursively scans adjacent elements of the array:
If size == 0, it returns 0.
If size == 1, it returns 1 (counting the last group/element).
If S[0] != S[1], it adds 1 and recurses on the rest of the array (foo(S+1, size-1)).
If S[0] == S[1], it simply recurses on foo(S+1, size-1) without adding 1.
Essentially, the function counts the number of contiguous blocks/runs of identical consecutive elements (or equivalently, the number of transitions between different consecutive elements plus 1 for the final element).
Let us trace the execution for array A={0,1,2,2,2,0,0,1,1} with size=9:
foo(A, 9): A[0]=0,A[1]=1⟹0=1⟹1+foo(A+1,8)
foo(A+1, 8): A[1]=1,A[2]=2⟹1=2⟹1+foo(A+2,7)
foo(A+2, 7): A[2]=2,A[3]=2⟹2==2⟹foo(A+3,6)
foo(A+3, 6): A[3]=2,A[4]=2⟹2==2⟹foo(A+4,5)
foo(A+4, 5): A[4]=2,A[5]=0⟹2=0⟹1+foo(A+5,4)
foo(A+5, 4): A[5]=0,A[6]=0⟹0==0⟹foo(A+6,3)
foo(A+6, 3): A[6]=0,A[7]=1⟹0=1⟹1+foo(A+7,2)
foo(A+7, 2): A[7]=1,A[8]=1⟹1==1⟹foo(A+8,1)
foo(A+8, 1): Base case size == 1 reached, returns 1.
Summing all returned values:
Result=1+1+0+0+1+0+1+0+1=5 Thus, the printed value is 5.