main()
{
int i=5;
printf("%d%d%d%d%d%d",i++,i--,++i,--i,i);
}
Answers were Sorted based on User's Feedback
Answer / abdul ahad
45545
because the expiration will executed from right to left and will print from left to right.
at the execution time from right i=5,--i=4,++i=5,i--=5 then decremented to4,now i++=4 ,then incremented to 5.
So the output will be left to right 45545
Is This Answer Correct ? | 105 Yes | 59 No |
Answer / prashant nair
Ans: It really much more depend on compiler.
The logic/rules made should take us to the answer 45545 but compiler does also give answer as 45555 :O
source:
http://code.hackerearth.com/bddbb9e
http://ideone.com/t5fbbd
Is This Answer Correct ? | 45 Yes | 9 No |
Answer / susie
Answer :
45545
Explanation:
The arguments in a function call are pushed into
the stack from left to right. The evaluation is by popping
out from the stack. and the evaluation is from right to
left, hence the result.
Is This Answer Correct ? | 21 Yes | 11 No |
Answer / rishit
And will be
4 5 5 4 5 and 1 garbage value as there are
6 %d in printf statement
Is This Answer Correct ? | 7 Yes | 2 No |
Answer / moschops
This is UNSPECIFIED BEHAVIOUR. It's possible to work out exactly what your particular compiler decided to do this one particular time, but other compilers are free to do it differently (and probably will). Put the code into some different compilers and you'll see different results. The order that parameters are evaluated is unspecified and left up to the compiler.
If you can explain what the compiler happens to do this one particular time, that's nice but completely useless, but anyone who actually wrote code like this should be fired.
Is This Answer Correct ? | 10 Yes | 6 No |
Answer / dharmendra
(i++,i--,++i,--i,i)
(4 , 5, 5 , 4 ,5)
explanation:
executed from right to left
and
print left to right.
Is This Answer Correct ? | 11 Yes | 7 No |
void main() { static int i=5; if(--i){ main(); printf("%d ",i); } }
Write a program to print a square of size 5 by using the character S.
main() { static char names[5][20]={"pascal","ada","cobol","fortran","perl"}; int i; char *t; t=names[3]; names[3]=names[4]; names[4]=t; for (i=0;i<=4;i++) printf("%s",names[i]); }
main() { int a[10]; printf("%d",*a+1-*a+3); }
Cluster head selection in Wireless Sensor Network using C programming language.
void main() { if(~0 == (unsigned int)-1) printf(“You can answer this if you know how values are represented in memory”); }
main(int argc, char *argv[]) { (main && argc) ? main(argc-1, NULL) : return 0; } a. Runtime error. b. Compile error. Illegal syntax c. Gets into Infinite loop d. None of the above
main() { char str1[] = {‘s’,’o’,’m’,’e’}; char str2[] = {‘s’,’o’,’m’,’e’,’\0’}; while (strcmp(str1,str2)) printf(“Strings are not equal\n”); }
What is the hidden bug with the following statement? assert(val++ != 0);
main() { static int var = 5; printf("%d ",var--); if(var) main(); }
#include<stdio.h> void fun(int); int main() { int a; a=3; fun(a); printf("\n"); return 0; } void fun(int i) { if(n>0) { fun(--n); printf("%d",n); fun(--n); } } the answer is 0 1 2 0..someone explain how the code is executed..?
main() { int i=5; printf("%d%d%d%d%d%d",i++,i--,++i,--i,i); }