Can any one explain how output is 2?
Because the precedence of the assignment operator (=) is higher than the comma operator (,).
Therefore, the statement:
a = (1, 2), 3;
is equivalent to:
(a = (1, 2)), 3;
and the expression (1, 2) evaluates to 2.