foo(char c) prints out the character it receives and then returns true. When the for loop is initialized, foo('A') is called. This prints out the 'A' that you see. Then the
test condition is evaluated -- foo('B') && i<2 -- foo('B') prints out the 'B'. On the first iteration, i=0 so the compound expression is true and the body of the for loop is executed: i is incremented and foo('D') is run, which prints out 'D'. Then the 'increment' portion of the for loop is run, which is foo('C') -- this prints out C.
Output so far: A B D C
Then the test condition is evaluated again. foo('B') prints out 'B' and returns true, and i is still less than 2, as it is now 1. Thus the body is executed and i becomes 2 and 'D' is output. The 'increment' portion is run again and 'C' is output.
Output so far: A B D C B D C
Finally the test condition is evaluated again, which prints out 'B'. So foo('B') returns true, but !(i<2) so the loop terminates.
Final Output: A B D C B D C B