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
Is there a way to switch on strings?
What is meant by high-order and low-order bytes?
what is the differnce between programing langauge and tool? is sas is a programing langauge r tool?
Why do we use & in c?
What are linker error?
How can I automatically locate a programs configuration files in the same directory as the executable?
What are the advantage of c language?
What is time complexity c?
‘SAVEPOINT’ and ‘ROLLBACK’ is used in oracle database to secure the data comment. Give suitable examples of each with sql command.
Why is struct padding needed?
What is %d used for?
What is the basic structure of c?
How do shell structures work?
What is the explanation for modular programming?
Explain what are preprocessor directives?