How it works ?
This is one of question asked in interview. This program based on half adder circuit. In half adder , summation is produce result of ex-or of two bits carry produce result of and of two bits. Now the logic in this program is if carry exists, we should do ex-or operation with addition and carry which is shifted 1 position.
in this program
when add function is called a=1 b=2. If(!a) won't true. So else will work. It call add function itself (recursive function) with values add operation of a and b and shifted one position left.add operation is
0000 and this will shifted one position left. Now it's same zero.
and ex-or operation is
now this two two values passed to add function. Now if(!a) work. Because not of 0's will 1's so it'll return b as sum of a and b.