The Gateway to Computer Science Excellence
0 votes
116 views
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;
closed as a duplicate of: Undefined Behaviour in C
in Programming by (167 points)
closed by | 116 views
0
it is compiler dependent we cant assume the associativity in terms of increment nd decrement
0
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?
+1
NOTHING LIKE THIS WILL BE IN GATE AS FAR AS I KNOW

1 Answer

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:

by Active (1.3k points)
0

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

+1

Thanks @Arjun sir. I understood the concept.

Related questions

Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true
50,644 questions
56,517 answers
195,583 comments
101,143 users