| | |
post decriment in while
![]() |
•
•
Join Date: Oct 2006
Posts: 34
Reputation:
Solved Threads: 1
I hav one doubt regarding post decriment,the code in c is as follows.............
void main()
{
clrscr();
while(i--!=6)
i=i+2;
printf("%d\n",i);
getch();
}
I know the output is 5, but i read in a book dat the post incriment or decrement operators are evaluated after reaching semicolon(
.....but in while condition,the ondition fails so it wont execute the next line so, directly reaches printf.Till now there is no semicolon still the i value is decresed......wts da reason...can u sugest me..?
Thanks & Regards.
void main()
{
clrscr();
while(i--!=6)
i=i+2;
printf("%d\n",i);
getch();
}
I know the output is 5, but i read in a book dat the post incriment or decrement operators are evaluated after reaching semicolon(
.....but in while condition,the ondition fails so it wont execute the next line so, directly reaches printf.Till now there is no semicolon still the i value is decresed......wts da reason...can u sugest me..?Thanks & Regards.
•
•
Join Date: May 2004
Posts: 178
Reputation:
Solved Threads: 10
Wow.
You do realize that your while loop subtracts then adds to the same variable, essentially in the same statement. Eeeek...
Back up.
What are you trying to do?
C Syntax (Toggle Plain Text)
void main() - don't use void main. main() returns an int. { clrscr(); while(i--!=6) - where is i set to some intitial value? i=i+2; - this is the end of the while loop I think you are missing {} to make a while block? printf("%d\n",i); getch(); }
Back up.
What are you trying to do?
![]() |
Similar Threads
- one away from my hundredth! (Geeks' Lounge)
- No display durring post with new mobo-- (Motherboards, CPUs and RAM)
- will not post (Troubleshooting Dead Machines)
- POST Problem (Troubleshooting Dead Machines)
- computer would not go through post... (Windows NT / 2000 / XP)
Other Threads in the C Forum
- Previous Thread: pascal triangle
- Next Thread: Problem with using % !
| Thread Tools | Search this Thread |
adobe api array arrays binarysearch calculate char cm convert copyanyfile copypdffile cprogramme createcopyoffile createprocess() csyntax directory dynamic feet fflush file floatingpointvalidation fork forloop frequency getlasterror givemetehcodez global graphics gtkgcurlcompiling hacking hardware highest homework i/o inches incrementoperators intmain() iso kernel kilometer km linked linkedlist linux linuxsegmentationfault list locate logical_drives loopinsideloop. match matrix microsoft motherboard mqqueue mysql oddnumber odf open opendocumentformat opensource openwebfoundation owf pattern pdf performance pointer posix power probleminc program programming pyramidusingturboccodes read recursion recv recvblocked repetition research scanf scheduling segmentationfault send shape socketprograming socketprogramming stack standard strchr string suggestions systemcall test unix urboc user variable voidmain() wab win32api windows.h





