Does the input buffer gets cleared after scanf reads?
问题 Does the input buffer gets cleared after scanf reads? #include <stdio.h> int main(void) { int a, b; scanf("%d", &a);//I inputted 3 scanf("%d", &b);//I inputted 4 } So when I gave the input 4 was 3 present in the input buffer? 回答1: So when I gave the input 4 was 3 present in the input buffer? No, the 3 was consumed. You cannot re-read it (as int or otherwise). If you input "3<enter>" the 3 is consumed and the buffer contains just the "<enter>" . You then type "4<enter>" which is added to the