void main()
{
int i=5;
printf("%d",i+++++i);
}
Answers were Sorted based on User's Feedback
Answer / visu
i+++++i=i++ + ++i
remember this expression is nothing but adding two i's
now unary operators hav higher precedence than binary
=>++ executes first
so i++ =5 (since value changes after statement)
and ++i makes it i=6
as i said its jus adding to i's
now ans=i+i=6+6=12
Is This Answer Correct ? | 15 Yes | 5 No |
Answer / surenda pal singh chouhan
Compiler Error
Explanation:
The expression i+++++i is parsed as i ++ ++ + i which is an
illegal combination of operators.
Is This Answer Correct ? | 17 Yes | 9 No |
Answer / 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 |
Answer / sheetal
gives error
"error C2105: '++' needs l-value"
because it parses above expression in "((i++)++)+i), so in
2nd unary operator it searches for l-value.
If we modify above pgm into following way:-
void main()
{
int i=5;
printf("%d",((i++)+(++i)));
}
it will give answer 12.
because once last pre-unary increment operator is operated,
i is incremented to 6 and 6+6 = 12.
if we put one more print for i's value, it will give i =7.
because first post-increment operator is operated after
first printf statement as follows.
void main()
{
int i=5;
printf("%d",((i++)+(++i)));
printf("%d\n",i); // ===> i =7
}
Is This Answer Correct ? | 4 Yes | 1 No |
Answer / visu
hey sulochana hav u tried it in a compiler..
cuz for me the result for that is 12.
i+++++i might give u an error but for sure (i++ + ++i)=12
Is This Answer Correct ? | 7 Yes | 5 No |
Answer / vamsi
Hi Guys.....
The answer is
6+6 = 12
The compiler will take the expression as
i++ + ++i
And the expression would be evaluated from Right to left ...
so answer is 12 and i=7;
Is This Answer Correct ? | 1 Yes | 0 No |
What's the difference between a linked list and an array?
const char * char * const What is the differnce between the above tow?.
Give the output for the following program. #define STYLE1 char main() { typedef char STYLE2; STYLE1 x; STYLE2 y; clrscr(); x=255; y=255; printf("%d %d\n",x,y); }
what is the return value (status code) of exit() function.... what the arguments(integer value) passed to it means....
What is a struct c#?
Where does the name "C" come from, anyway?
What is the difference between constant pointer and constant variable?
macros and function are related in what aspect? a)recursion b)varying no of arguments c)hypochecking d)type declaration
12 Answers HCL, Infosys, Microsoft,
how to print value of e(exp1)up to required no of digits after decimal?
Not all reserved words are written in lowercase. TRUE or FALSE?
how to make c program without a libary? e.g.#include<stdio.h> libary is not in c progaram.
which do you prefer C or Pascal?