clear buffer memory in c / c++

To clear the buffer memory in C/C++, you can follow these steps:

  1. Include the necessary header file: #include <stdlib.h>

  2. Use the fflush() function to clear the buffer memory. It takes a pointer to the file stream you want to clear. To clear the standard input buffer, use fflush(stdin). For example:

fflush(stdin);
  1. Alternatively, you can use the getchar() function to clear the buffer memory. It reads a single character from the standard input and discards it. For example:
int c;
while ((c = getchar()) != '\n' && c != EOF);

These steps will help you clear the buffer memory in C/C++.