ans:4 exp:here in the statement a <<=c>b>a^a relational greater & less than operators, 3) ^ binary xor operator 4) assignment = operator
now if look at the statement carefully the left shift can't be evaluated first this is because its shift value is to be returned by the assignment operator= which is a<<=c and assignment as i said has least priority!
so first the relational operators are evaluated here again the greater than and less-than operator have same priority, whenever two operators have same priority then they are evaluated according to their associativity which in this case is from left to right so the statment is evaluated like this:
a<<=c>b>a^a3>2^2<5<3; a<<=1>2^2<5<3; operation: 5>3 a<<=0^2<5<3;operation : 1>2 a<<=0^1<3; operation:2<5 a<<=0^1; operation:1<3 a<<=1; operation:0^1 a<<1; operation:= the above is same as 2<<1 which is 4 hence the op
Manoj you are absolutely right.As in the given expression < and > having same priority.So execution will be Left -> Right.I must say this is one of the fantastic question.
I have removed my previous comment.Just i don't want to confuse anybody,as i got.Hats off to respected sir and Manoj to you also.Thanks in taking me much deeper n deeper.
That is one good look at operator precedence ! Well done , once again. I would love to see some more competition. Soumen & Manoj Thanks for your efforts. I shall remove the variations in timings while posting the C program exercises.
FROM MONDAY, THE PROGRAM WILL BE AVAILABLE AT 5AM(IST) SHARP.
ans:4
ReplyDeleteexp:here in the statement
a <<=c>b>a^a relational greater & less than operators,
3) ^ binary xor operator
4) assignment = operator
now if look at the statement carefully the left shift can't be evaluated first this is because its shift value is to be returned by the assignment operator= which is a<<=c and assignment as i said has least priority!
so first the relational operators are evaluated here again the greater than and less-than operator have same priority, whenever two operators have same priority then they are evaluated according to their associativity which in this case is from left to right
so the statment is evaluated like this:
a<<=c>b>a^a3>2^2<5<3;
a<<=1>2^2<5<3; operation: 5>3
a<<=0^2<5<3;operation : 1>2
a<<=0^1<3; operation:2<5
a<<=0^1; operation:1<3
a<<=1; operation:0^1
a<<1; operation:=
the above is same as
2<<1 which is 4
hence the op
This comment has been removed by the author.
ReplyDeleteManoj you are absolutely right.As in the given expression < and > having same priority.So execution will be Left -> Right.I must say this is one of the fantastic question.
ReplyDeleteI have removed my previous comment.Just i don't want to confuse anybody,as i got.Hats off to respected sir and Manoj to you also.Thanks in taking me much deeper n deeper.
That is one good look at operator precedence !
ReplyDeleteWell done , once again.
I would love to see some more competition.
Soumen & Manoj Thanks for your efforts.
I shall remove the variations in timings while posting the C program exercises.
FROM MONDAY, THE PROGRAM WILL BE AVAILABLE AT 5AM(IST) SHARP.