The getchar() statement uses the

getchar() function to get and return the next character from STDIN (standard input). If it reaches the end of the file, return EOF.

C to execute the input statement, wait until the user enters the data and hits It does not start until you enter the Enter key. The data entered by the user and the Enter key are both in the input buffer. The input statement is taken from the buffer in turn. The next input statement, first find the number that has not been read in the buffer. If there is a number of buffers, use it. If not, wait until the user enters the Enter key and then start fetching.

语法:#include <stdio.h>
  int getchar( void );

#include <iostream>
#include <stdio.h>

using namespace std;

int main()
{
    char x;
    printf("Enter 1 please: ");
    x=getchar();
    putchar(x);
    x=getchar(); // Absorb Enter, where you can test separately and comment out, find the feeling 
    printf("\n");
    printf("Enter 2 please: ");
    x=getchar();
    putchar(x);
    return 0;
}

叫你打1, but only play 1 without Enter key, The input statement does not begin execution. If you hit 1 and hit the Enter key, getchar(); just use 1 and the rest of the Enter key is still in the buffer. If you don't need to absorb the Enter sentence, printf("Enter 2 please: "); Getchar(); Just wait for your input, take the Enter from the buffer, and the program ends.