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 difference between malloc() and calloc()?
Explain what are bus errors, memory faults, and core dumps?
What are the different types of data structures in c?
What is the c value paradox and how is it explained?
How do you use a 'Local Block'?
write a program which the o/p should b in such a way that s triangle if I/p is 3,a Square/rectangle if I/P=4,a pentagon if I/P=5 and so on...forget about the I/P which is less than 3
What does. int *x[](); means ?
What are qualifiers in c?
If a five digit number is input through the keyboard, write a program to print a new number by adding one to each of its digits.For example if the number that is input is 12391 then the output should be displayed as 23402
write a program in c language to print your bio-data on the screen by using functions.
What do you mean by invalid pointer arithmetic?
How can I manipulate strings of multibyte characters?
Write the control statements in C language
Why is sprintf unsafe?
What is static memory allocation?