main()
{ int i;
printf("%d",((i=1)*i-- - --i*(i=-3)*i++ + ++i));
}
ans is 24 bt how?pls tell smbody............
Answers were Sorted based on User's Feedback
Answer / gorgeousgirl
Answer: 34
confirm the answer with http://codepad.org/PudiZIaS
Explanation:
by order of precedence, parenthesis hav highest priority
so
(i=1)*i-- - --i*(i=-3)*i++ + ++i
i=1 i=-3
now, i=-3
after assignment operations the expr becomes,
>(i)*i-- - --i*(i)*i++ + ++i
next higher priority is for auto-in/decrement
omitting post in/decrement(as they hav effect only after
this line of code), we get,
> i*i - --i*i*i + ++i
the associativity for printf statement is from right to left
so ++i is executed first before --i where i=-3
> i*i - --i*i*i + -2
now i=-2
> i*i - -3*i*i + -2
now i =-3
next precedence is for multiplication
> -3*-3
-
-3*-3*-3
+
-2
> 9 - -27 + -2
> 9 + 27 -2
> 9 + 25
> 34
Is This Answer Correct ? | 3 Yes | 0 No |
Answer / sureshb
value is 26 and i value is -2.
Intiallay i=1 is assiged.
((i=1)*i--) 1st expression = 1 postfix decrement evaluates at the end.
now i=1
--i => 0. 2nd expression
i=-3 assigned new value 3rd expression.
-3*-3 => 9 *(-3) => -27
++ post increment done at the end
-(-27) = 27.
1+ 27 =>28
now i is -3.
++i => -2;
28-2= 26.
i=-2;
post increment and decrement happens. finaaly i = -2.
Is This Answer Correct ? | 5 Yes | 3 No |
Answer / rama krishna sidhartha
Actually answer is not 24 it is -7567. When i executed this
in the turbo c compiler i got the answer like that.
Is This Answer Correct ? | 0 Yes | 2 No |
What is the result main() { char c=-64; int i=-32 unsigned int u =-16; if(c>i){ printf("pass1,"); if(c<u) printf("pass2"); else printf("Fail2");} else printf("Fail1); if(i<u) printf("pass2"); else printf("Fail2") } a)Pass1,Pass2 b)Pass1,Fail2 c)Fail1,Pass2 d)Fail1,Fail2 e)none
What is the use of ?
Write a program that takes a 5 digit number and calculates 2 power that number and prints it(should not use big integers and exponential functions)
2 Answers HCL, IBM, Satyam, Vimal, Vimukti Technologies,
What are the keywords in c?
What is a struct c#?
write a c program to print "Welcome" without using semicolon in the whole program ??
write a c program to find reminder and quotient if one number is divided by other.to code this program don't use more than 2 variables
Does c have function or method?
What is Bitwise Operator and how it works?
what is the use of getch() function in C program.. difference b/w getch() and getche()??
29 Answers HCL, IBM, Infosys, TCS, Wipro,
What does a function declared as pascal do differently?
which of the following go out of the loopo if expn 2 becoming false a.while(expn 1){...if(expn 2)continue;} b.while(!expn 1){if(expn 2)continue;...} c.do{..if(expn 1)continue;..}while(expn 2); d.while(!expn 2){if(expn 1)continue;..}