1 votes 1 votes What will be the output of following program? void main() { int i=1; printf("%d",i=++i==1); } A)0 B)1 C)2 D)error Sankaranarayanan P.N asked Sep 28, 2016 Sankaranarayanan P.N 709 views answer comment Share Follow See all 12 Comments See all 12 12 Comments reply Show 9 previous comments srestha commented Sep 28, 2016 reply Follow Share yes it is a sequence point problem as i is changing more than one time before semicolon. 0 votes 0 votes sourav. commented Sep 28, 2016 reply Follow Share no i mean that no use of wasting discussions in undefined behaviour which is out of scope of gate ! it would be worth if the domain of undefined behaviour is limited ,but as it is limitless so it would be impractical discussing ! :) 0 votes 0 votes ManojK commented Sep 28, 2016 reply Follow Share yes ofcourse undefined one. 0 votes 0 votes Please log in or register to add a comment.
Best answer 2 votes 2 votes The following code can be simplified to printf("%d",(i=((++i)==1)); $\Rightarrow$ ++i making i=2 $\Rightarrow$ $2\neq 1$ resulting 0 $\Rightarrow$ 0 is assigned to i above steps is followed using http://www.difranco.net/compsci/C_Operator_Precedence_Table.htm sourav. answered Sep 28, 2016 • selected Sep 29, 2016 by Sankaranarayanan P.N sourav. comment Share Follow See all 0 reply Please log in or register to add a comment.