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
How are Structure passing and returning implemented by the complier?
find the value of y y = 1.5x+3 for x<=2 y = 2x+5 for x>2
What are enums in c?
What are nested functions in c?
Describe static function with its usage?
An expression to whose value an operater is applied a) operand b) variable c) constant d) all of the above
Can two or more operators such as and be combined in a single line of program code?
How do you do dynamic memory allocation in C applications?
Explain zero based addressing.
What is the use of structure padding in c?
what is the difference between north western polytechnique university and your applied colleges?? please give ur answers for this. :)
Is null always defined as 0(zero)?
How many types of sorting are there in c?
`write a program to display the recomended action depends on a color of trafic light using nested if statments
What is the meaning of 2d in c?