in Programming in C
1,305 views
0 votes
0 votes

in Programming in C
1.3k views

4 Comments

a*b*c => either you do (a*b)*c or a*(b*c), result is same. So you can't identify the order of evaluation.

Similarly,

a+b+c =(a+b)+c=a+(b+c)

a&&b&&c = (a&&b)&&c = a&&(b&&c)

but in case of % =>

a%b%c => (a%b)%c ≠a%(b%c)

therefore, based on the result, you can find out the order of evaluation.

@Rishav Kumar Singh  Is my answer correct?

0
0

@Ashish Goyal

brother order of evaluation means, which one evaluates first, it doesn't depend upon result.

in C, they defined the order of evaluation for only 4 operators

1) expr1 && expr2   ====> expr1 evaluates first if it true then only expr2 evaluates

2) expr1 || expr2   ====> expr1 evaluates first if it false then only expr2 evaluates

3) expr1 , expr2   ====> expr1 evaluates first then expr2 evaluates and return the value of expr2

4) expr1 ? expr2 : expr3   ====> expr1 evaluates first if ( it true then only expr2 evaluates) else ( then only expr3 evaluates )

2
2
@Shaik Masthan

Thanks for the elaboration. I misunderstood the question. It is clear now
0
0

1 Answer

1 vote
1 vote
Best answer

The answer is && i.e. option D since the order of evaluation for the operator & & is defined by the language whereas * and + will be evaluated  depending on the type of Associativity.

selected by