what is the output of following program ?
void main()
{
int i=5;
printf("%d %d %d %d %d ",i++,i--,++i,--i,i);
}
Answers were Sorted based on User's Feedback
Answer / sameeksha agrawal
ya i can tell u abt d ans ..the reasn behind it x++ is
example of post increament in which frstly value of any
variable is prnt thn oprtr r prfrmed and the oprtions r
perfrmd frm right side...
| Is This Answer Correct ? | 7 Yes | 2 No |
Answer / sandeep gupta
Friends, actually the output is compiler dependent. Never
give any specific answer in this type of questions because C
does not provide any format in evaluation order of postfix
and prefix expressions when passed to any functions like
printf() eg. fun1(i++,i) may pass fun1(5,6) in some
compilers and fun1(5,5) in another. So it totally depends on
what compiler we're using.
| Is This Answer Correct ? | 4 Yes | 0 No |
Answer / jalp
Here if i do it manually then i got 44545 but compiler shows
me : 45545
Can any body show the stack process that how it execute
internally,
And also reply through mail.
Thanks.
| Is This Answer Correct ? | 6 Yes | 5 No |
Answer / jalp
That i know .. I want to know the stack process , how it
internally works .. if you elaborate through step then
please explain it ..
Thanks.
| Is This Answer Correct ? | 2 Yes | 1 No |
Answer / kavsac
Guys,
There is something, I wanna add on. The above result occurs only in windows, in Unix its 56656
| Is This Answer Correct ? | 2 Yes | 1 No |
Answer / shenbagam
in c its left to right operation will be perfomed by
compiler..... so take this
int i=5;
printf("%d %d %d %d %d ",i++,i--,++i,--i,i);
i=5;
--i=4; after tis the value of i=4 only;
because --i will decrement the value of i, and then return the decremented value.
++i=5; after this the value of i=5;
because ++i will increment the value of i, and then return the incremented value.
i--=5; after this the value of i=4;
because will decrement the value of i, but return the pre-defind value of i. so i=5 before the step na?.....
i++=4; after this the value of i=5;
because will increment the value of i, but return the pre-defined value of i.so i=4 before the step na?...
so only the result will be like 45545 this.......
int i=5;
printf("%d %d %d %d %d ",i++,i--,++i,--i,i);
after the step if u print i; the value must be 5
only......... so the doubt will be cleared aha?............
all the best:):):):).
| Is This Answer Correct ? | 4 Yes | 3 No |
Answer / sameeksha agrawal
no Kavsac u r wrng try again its answer...
| Is This Answer Correct ? | 0 Yes | 0 No |
Answer / sameeksha agrawal
sry u r totally wrng cz c is structrd progrmmmng languaga
| Is This Answer Correct ? | 0 Yes | 0 No |
Answer / sindhu
Answer:after compilation i got 45545.... but if i consider it from left to right in manual my answer is 55454...
i want clear xplanation for tis program...
| Is This Answer Correct ? | 0 Yes | 0 No |
void main() { unsigned giveit=-1; int gotit; printf("%u ",++giveit); printf("%u \n",gotit=--giveit); }
main() { int i = 3; for (;i++=0;) printf(ā%dā,i); }
writte a c-programm to display smill paces
why array index always strats wuth zero?
Given an array of size N in which every number is between 1 and N, determine if there are any duplicates in it. You are allowed to destroy the array if you like.
21 Answers ABC, eBay, Goldman Sachs, Google, HUP, Microsoft, TATA,
main() { int i=-1,j=-1,k=0,l=2,m; m=i++&&j++&&k++||l++; printf("%d %d %d %d %d",i,j,k,l,m); }
/*what is the output for*/ void main() { int r; printf("Naveen"); r=printf(); getch(); }
main() { unsigned int i=10; while(i-->=0) printf("%u ",i); }
main() { extern int i; i=20; printf("%d",i); }
what is the output of following program ? void main() { int i=5; printf("%d %d %d %d %d ",i++,i--,++i,--i,i); }
How can you relate the function with the structure? Explain with an appropriate example.
main() { int a=10,*j; void *k; j=k=&a; j++; k++; printf("\n %u %u ",j,k); }