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
What is the Purpose of 'extern' keyword in a function declaration?
Which control loop is recommended if you have to execute set of statements for fixed number of times?
Who developed c language and when?
When c language was developed?
Do you know pointer in c?
How does selection sort work in c?
Difference between linking and loading?
How can I ensure that integer arithmetic doesnt overflow?
What do you mean by invalid pointer arithmetic?
Are the variables argc and argv are always local to main?
What is typedef?
What is the mean of function?
Explain what is a 'locale'?
Write an efficient algo and C code to shuffle a pack of cards.. this one was a feedback process until we came up with one with no extra storage.
Write a code to generate a series where the next element is the sum of last k terms.