The while loop is actually quite horrid. I’ve never seen code like this in real life, and would declare any programmer doing it in real life as mad. We need to go through this step by step:
while (condition);
We have here a while statement with an empty statement (the “;” alone is an empty statement). The condition is evaluated, and if it is true, then the statement is executed (which does nothing because it is an empty statement) and we start all over again. In other words, the condition is evaluated repeatedly until it is false.
condition1 || condition2
This is an “or” statement. The first condition is evaluated. If it is true, then the second condition is not evaluated and the result is “true”. If it is false, then the second condition is evaluated, and the result is “true” or “false” accordingly.
while (condition1 || condition2);
This evaluates the first condition. If it’s true we start all over. If it is false, we evaluate the second condition. If that is true, we start all over. If both are false, we exit the loop. Note that the second condition is only evaluated if the first one is false. Now we look at the conditions:
!*p1++
!*p2++
This is the same as *(p1++) == 0 and *(p2++) == 0. Each condition increases p1 or p2 after it has been evaluated, no matter what the outcome. Each condition is true if *p1 or *p2 was zero and false otherwise. Now we check what happens at each iteration:
p1 = &t1 [0], p2 = &t2 [0]
*p1++ == 0 is true, *p2++ == 0 is never evaluated, p1 = &t1 [1], p2 = &t2 [0].
*p1++ == 0 is true, *p2++ == 0 is never evaluated, p1 = &t1 [2], p2 = &t2 [0].
*p1++ == 0 is false, *p2++ == 0 is true, p1 = &t1 [3], p2 = &t2 [1].
*p1++ == 0 is false, *p2++ == 0 is true, p1 = &t1 [4], p2 = &t2 [2].
*p1++ == 0 is false, *p2++ == 0 is false, p1 = &t1 [5], p2 = &t2 [3].
t1 is the same as &t1 [0]. p1 – t1 == &t1 [5] – &t1 [0] == 5.
t2 is the same as &t2 [0]. p2 – t2 == &t2 [3] – &t2 [0] == 3.