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 60 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

how to swap 3 nos without using temporary variable

4 Answers   Satyam,


Cluster head selection in Wireless Sensor Network using C programming language.

0 Answers  


main() { static int a[3][3]={1,2,3,4,5,6,7,8,9}; int i,j; static *p[]={a,a+1,a+2}; for(i=0;i<3;i++) { for(j=0;j<3;j++) printf("%d\t%d\t%d\t%d\n",*(*(p+i)+j), *(*(j+p)+i),*(*(i+p)+j),*(*(p+j)+i)); } }

1 Answers  


In the following pgm add a stmt in the function fun such that the address of 'a' gets stored in 'j'. main(){ int * j; void fun(int **); fun(&j); } void fun(int **k) { int a =0; /* add a stmt here*/ }

1 Answers  


Who could write how to find a prime number in dynamic array?

1 Answers  






How to palindrom string in c language?

6 Answers   Google,


main( ) { char *q; int j; for (j=0; j<3; j++) scanf(“%s” ,(q+j)); for (j=0; j<3; j++) printf(“%c” ,*(q+j)); for (j=0; j<3; j++) printf(“%s” ,(q+j)); }

1 Answers  


what is the code of the output of print the 10 fibonacci number series

2 Answers  


void main () { int x = 10; printf ("x = %d, y = %d", x,--x++); } a. 10, 10 b. 10, 9 c. 10, 11 d. none of the above

2 Answers   HCL,


How do you create a really large matrix (i.e. 3500x3500) in C without having the program crash? I can only reach up to 2500. It must have something to do with lack of memory. Please help!

1 Answers  


main() { int i=3; switch(i) { default:printf("zero"); case 1: printf("one"); break; case 2:printf("two"); break; case 3: printf("three"); break; } }

1 Answers  


main() { int c[ ]={2.8,3.4,4,6.7,5}; int j,*p=c,*q=c; for(j=0;j<5;j++) { printf(" %d ",*c); ++q; } for(j=0;j<5;j++){ printf(" %d ",*p); ++p; } }

2 Answers   CSS, Wipro,


Categories