0 0 votes closed as a duplicate of: Undefined Behaviour in C X=2; Y=++x * ++x * ++x ; Printf("%d",Y); In the above question, we have to use the final value of x or it will be evaluated seperately and then multiplied. Ex: Y= 3*4*5; or Y=5*5*5; Programming in C self-doubt programming-in-c output + – Ashish Roy 1 1.3k views comment Share Follow Print See all 3 Comments 3 3 Comments reply eyeamgj commented Apr 11, 2019 reply Follow flag it is compiler dependent we cant assume the associativity in terms of increment nd decrement 0 0 replyShare Ashish Roy 1 commented Apr 11, 2019 reply Follow flag Okay. Suppose it is a NAT, then what should be the answer. Or it is inside a program and for getting the output of the program value of Y is required then what must be the answer? 0 0 replyShare eyeamgj commented Apr 11, 2019 reply Follow flag NOTHING LIKE THIS WILL BE IN GATE AS FAR AS I KNOW 1 1 replyShare Please log in or register to add a comment.
0 0 votes Since pre increment and pre decrement have right associativity. Pre increment and decrement operator have more precedence than multiplication operator. Therefore , In Y=(++x)*(++x)*(++x), evaluation is done as follows: SuvasishDutta answered Apr 18, 2019 SuvasishDutta comment Share Follow See all 2 Comments 2 2 Comments reply Arjun commented Apr 18, 2019 reply Follow flag Evaluation order is separate from the associativity order. Associativity only specifies the operands for the operators and when and how the operands are evaluated is independent of it. https://gateoverflow.in/62411/undefined-behaviour-in-c 0 0 replyShare SuvasishDutta commented Apr 22, 2019 reply Follow flag Thanks @Arjun sir. I understood the concept. 1 1 replyShare Please log in or register to add a comment.