look
we have this thing
int a,b;
a=3;
b=a++ +(a=3)+ ++a;
for this expresson we get b=9 in c and b=10 in java
while a=4..
can anybody give me proper reasons for why is that happening....
acc. to me the curly brackets have the highest priority in the expression so they are evaluated first.....but that is not solving my problem..please help.
Different answers for same expresson in java and c...expression is b=a++ +(a=3)+ ++a?
b=a++ + (a=3) + ++a;
first does a++ which will be 3 (4 after execution)
then does (a=3) which will be 3
then does (++a) which will be 4
gives you b=3 + 3 + 4 = 10 and a=4
I am not sure why it give b=9 in c as it should give b=10. I tried it in c# and it gives 10. there may be something wrong with your initialization in c
Reply:It depends on the way the compiler is implemented to handle the expression.
For example take C language.
There are many compilers available such as TurboC,Borland C,Microsoft C etc.
Each compilers has its own implementations.
Some compilers will process a expression from right to left and some will proces from left to right.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment