Using the AND_THEN operator avoids a null pointer exception at runtime. However, since the first operand of the AND_THEN operator returns FALSE (since 'pSample' has the value 0), the other AND_THEN operands and thus pointer dereferencing are not executed.
The background is that the AND_THEN operator is used, and dereferencing would take place at the other operands of the AND_THEN operator. Therefore, the results for the four expressions shown here are as follows: Note that OR has the weakest binding and that TwinCAT executes expressions at other operands of the AND_THEN operator only if the first operand of the AND_THEN operator is TRUE. In the following example the operators AND_THEN and OR are used. Operators with the same binding strength are processed from left to right. TwinCAT first processes the operator with the strongest binding.
The evaluation of an expression is carried out by processing the operators according to certain binding rules.