main()

{

int i=5;

printf("%d%d%d%d%d%d",i++,i--,++i,--i,i);

}

Answers were Sorted based on User's Feedback



main() { int i=5; printf("%d%d%d%d%d%d",i++,i--,++i,--i,i); ..

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

main() { int i=5; printf("%d%d%d%d%d%d",i++,i--,++i,--i,i); ..

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

main() { int i=5; printf("%d%d%d%d%d%d",i++,i--,++i,--i,i); ..

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

main() { int i=5; printf("%d%d%d%d%d%d",i++,i--,++i,--i,i); ..

Answer / jaya

ans:- 45545

Is This Answer Correct ?    13 Yes 7 No

main() { int i=5; printf("%d%d%d%d%d%d",i++,i--,++i,--i,i); ..

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

main() { int i=5; printf("%d%d%d%d%d%d",i++,i--,++i,--i,i); ..

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

main() { int i=5; printf("%d%d%d%d%d%d",i++,i--,++i,--i,i); ..

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

Post New Answer

More C Code Interview Questions

main() { int i, j; scanf("%d %d"+scanf("%d %d", &i, &j)); printf("%d %d", i, j); } a. Runtime error. b. 0, 0 c. Compile error d. the first two values entered by the user

2 Answers   HCL,


Give a one-line C expression to test whether a number is a power of 2.

10 Answers   Microsoft,


How to read a directory in a C program?

4 Answers  


Write a C function to search a number in the given list of numbers. donot use printf and scanf

5 Answers   Honeywell, TCS,


How do you sort a Linked List (singly connected) in O(n) please mail to pawan.10k@gmail.com if u can find an anser...i m desperate to knw...

6 Answers   Microsoft, MSD, Oracle,






#include<stdio.h> main() { const int i=4; float j; j = ++i; printf("%d %f", i,++j); }

1 Answers  


How to return multiple values from a function?

7 Answers  


main() { unsigned int i=65000; while(i++!=0); printf("%d",i); }

1 Answers  


Write a procedure to implement highlight as a blinking operation

2 Answers  


void func1(int (*a)[10]) { printf("Ok it works"); } void func2(int a[][10]) { printf("Will this work?"); } main() { int a[10][10]; func1(a); func2(a); } a. Ok it works b. Will this work? c. Ok it worksWill this work? d. None of the above

1 Answers   HCL,


main() { int i = 257; int *iPtr = &i; printf("%d %d", *((char*)iPtr), *((char*)iPtr+1) ); }

1 Answers   CSC,


How to count a sum, when the numbers are read from stdin and stored into a structure?

1 Answers  


Categories