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
Can the curly brackets { } be used to enclose a single line of code?
What is the purpose of main( ) in c language?
What is the correct code to have following output in c using nested for loop?
Why is #define used?
What are the loops in c?
Does * p ++ increment p or what it points to?
What are the types of operators in c?
What is the difference between union and structure in c?
What is an auto variable in c?
can anyone please tell about the nested interrupts?
Differentiate between the expression “++a” and “a++”?
What are the difference between a free-standing and a hosted environment?
How many levels of pointers can you have?
Explain how can you avoid including a header more than once?
Is Exception handling possible in c language?