The expression uses the logical AND operator:
$\texttt{fork() \&\& fork()}$
The second $\texttt{fork()}$ is evaluated only when the first operand is nonzero.
For the first $\texttt{fork()}$ :
- The parent receives a positive value, so it executes the second $\texttt{fork()}$.
- The child receives $0$, so short-circuit evaluation prevents it from executing the second $\texttt{fork()}$.
The parent that executes the second $\texttt{fork()}$ produces:
- One parent for which the complete expression is true
- One child for which the second $\texttt{fork()}$ returns $0$
Therefore, there are three processes:
- First child $: \texttt{pid = 0}$, prints $\texttt{A}$
- Second child $: \texttt{pid = 0}$, prints $\texttt{A}$
- Original parent $:\texttt{pid = 1}$, prints $\texttt{B}$
Thus, $\texttt{A}$ is printed twice and $\texttt{B}$ is printed once.
Answer : C