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
When should you use a type cast?
What is the total generic pointer type?
What is nested structure with example?
int far *near * p; means
What is a lvalue
What is console in c language?
Can a function be forced to be inline? Also, give a comparison between inline function and the C macro?
Do you know what are the properties of union in c?
Explain the priority queues?
What does 2n 4c mean?
the portion of a computer program within which the definition of the variable remains unchanged a) mode b) module c) scope d) none
Explain what is a 'locale'?
Explain what is output redirection?
A collection of functions,calls,subroutines or other data a) library b) header files c) set of files d) textfiles
Why static variable is used in c?