void main()
{
int i=5;
printf("%d",i+++++i);
}

Answer Posted / jaroosh

This is a very interesting issue, to solve this, first you
have to note an interesting thing about pre and
postincrementation operators :
a) postincrementation operator instantly MAKES variable an
RVALUE in expression, this is because postincrement operator
doesnt keep track of how many postincrements were made so it
is NOT cumulative (ie u can only use one postincrementation
for variable)
b) preincrementational operator first increments variable
and THEN uses it in expression so there is no need to keep
track of how many preincrementations were made thus
preincrement is cumulative.
Following lines make the point :
i++ = 1; //WRONG! i++ becomes RVALUE,you cannot assign to it
++i = 1; //OK! you first incremented and then assigned.
and thus :
i++++; //WRONG! (i++) is RVALUE so you cannot (RVALUE)++
++++i; //OK! ++(++i)
Now, since postfic ++ has the higher precedence, :
i+++++i
is treaded like :
(i++)++ + i
which will throw compiler error.
i++ + ++i
is however fine, so as
i+ ++++i

This issue might be compiler specific, Im not sure.

Is This Answer Correct ?    5 Yes 2 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Can the curly brackets { } be used to enclose a single line of code?

718


What is the purpose of main( ) in c language?

628


What is the correct code to have following output in c using nested for loop?

616


Why is #define used?

794


What are the loops in c?

597






Does * p ++ increment p or what it points to?

621


What are the types of operators in c?

617


What is the difference between union and structure in c?

581


What is an auto variable in c?

762


can anyone please tell about the nested interrupts?

1680


Differentiate between the expression “++a” and “a++”?

709


What are the difference between a free-standing and a hosted environment?

748


How many levels of pointers can you have?

709


Explain how can you avoid including a header more than once?

607


Is Exception handling possible in c language?

1588