0

I have the following code about input and output in C.

#include <stdio.h>

int main(){
    int this_is_a_number;
    printf("Please enter a number: ");
    scanf("%d", &this_is_a_number);
    printf("You entered %d\n", this_is_a_number);
    getchar();
    return 0;
}

When I entered a number, the console displays "You have entered NUM" and just exit. My question is what does the getchar() do? (shouldn't the program wait for me to enter something and hit enter before it exits?). Thank you in advance!

melpomene
  • 84,125
  • 8
  • 85
  • 148

0 Answers0