| | |
post decriment in while
Please support our C advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
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 |
* ansi api array arrays bash binarysearch calculate centimeter changingto char character convert copyanyfile copypdffile creafecopyofanytypeoffileinc createcopyoffile createprocess() dynamic execv fflush file floatingpointvalidation fork forloop frequency function getlogicaldrivestrin givemetehcodez grade graphics gtkwinlinux histogram homework i/o ide inches include infiniteloop initialization input intmain() iso keyboard km license linked linkedlist linux list looping loopinsideloop. lowest matrix microsoft multi mysql oddnumber open opendocumentformat openwebfoundation overwrite pdf pointer pointers posix power program programming pyramidusingturboccodes radix read recursion recv recvblocked reversing scanf scheduling segmentationfault send shape single socketprogramming stack standard strchr string strings suggestions test testautomation testing threads unix urboc user variable whythiscodecausesegmentationfault win32api windowsapi





