c/c++ : operator concepts
presedence must be known
http://www.swansontec.com/sopc.htm
http://docs.roxen.com/pike/7.0/tutorial/expressions/operator_tables.xml
n + n + ++n = ??
for + associativity is left to right ie
n + n + ++n = (n + n) + ++n = whatever
in ( a + b ), b is evaluated first
++n + n v/s n + ++n
constants creates all the problem
0 + n + ++n = ??
constants are removed aside and than variables are evaluated.
ie 0 + n + ++n = 0 + ( n + ++n)
* sucks a lot
i * ++i * i++ = ??
unirary operatos are evaluated first, and then for the * expression the variable are used. ie in the above expression. ( left to right associativity and right evaluated first rules holds)
the steps are : (according to my interpretation, and works well for my compiler)
++i
i++
i * i * i
f***ing na!!






December 12th, 2004 at 5:32 pm
Date: Mon, 5 Jul 2004 17:43:01 +0530
From: MADDY ( pankaj -dot- madhukar -at- gmail… )
Saale 200 pe kya kar reha hai..har 2 second pe to network error aa reha hai..
tere ko 5 mail likhne ki koshish ki panchon ..har baar network error aaya aur
fir mera pura mesg khatm..:(
Khair..
Tune kaha tha 0 + n + ++n where n=0 ka output kyun 2 aata hai..
The reason i can think of it is..
The compiler evaluates the constants during
the formation of its postfix or prefix notation from the
infix form.And the postfix form or prefix form is evaluated
by first converting the expression in the form of
a + b + c + d -(1)
like wise. where a can be s*y where s and y can be other varriables.Its
postfix/prefix form will be evaluated before postfix / prefix of expression (1)
is evaluated.The evaluation of a + b + c follows ((a + b) + c).
Take ur example expression only
0 + n + ++n
The compiler evaluates it as ( 0 + n) + ++n
But 0 + n doesn’t mean 0 ..
0 + n means n
Thus
given n=0
0 + n + ++n = n + ++n = 2
or if u take another example like
0 + n + 0 + ++n = n + ++n =2
or take any other example like
given n=1
0 + n + 1 + 5 + ++n = 6 + n + ++n
= 6 + ( n + ++n)
= 10
Also take a more complicated example
given n=1
0 + n*3 + 1 + 5 + ++n = 6 + n*3 + ++n
= 6 + ( (n * 3) + ++n)
= 11
This is what i think, i dont know whether it is correct or not
Tell me if there is any problem with this explanation…
–
Pankaj Kumar Madhukar
IIIT-Hyderabad