I am reading K&R book, on page 63 there is a line
while (--lim > 0 && (c=getchar()) != EOF && c != '\n')
where lim is int equal to 1000
My question, why is lim is not decreasing after consequential runs of while loop ?
As I see it, –lim is equivalent to “lim = lim – 1”
===================================================================
Thanks for all the answers !
--limmeans “take one from the value oflimand use the result”.The alternative
lim--would be “use the value oflimand then take one away”.So if
limstarts at 1000 the first time the loop executes it will have the value999before it is checked to see if it’s greater than 0. If it werelim--then the value that would be checked would be1000, but it would still have the value of 999 at the end of the iteration through the loop. This is important at the start and end of the loop.The MSDN as a page on this Prefix Increment and Decrement Operators