Can’t understand the working of getint() in C as per K&R

The getint() function only reads digits from the input. If it gets a character that is not a digit or a + – sign at the beginning it will call ungetch() to push the character back into the input buffer so it could be read by some other function call. getint() will go on returning 0 until you remove the non-digit character from the input buffer by calling getch() on your own.

Leave a Comment