

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
What do you mean by buffer in C language?
A temporary storage area is called buffer. All input output (I/O) devices contain I/O buffer.
When we try to pass more than the required number of values as input then, the remaining values will automatically hold in the input buffer. This buffer data automatically go to the next input functionality, if it is exists.
We have to clear the buffer before the next input is taken in.
Example
Following is the C program for buffer −
#include<stdio.h> void main(){ int a,b; printf("\n Enter a value: "); scanf("%d",&a); printf("\n Enter b value: "); scanf("%d",&b); printf("\n a+b=%d ",a+b); getch(); }
Output
When the above program is executed, it produces the following result −
Enter a value: 1 Enter b value: 2 a+b=3
Again, run the program. This time, we try to enter values in a and not in b.
Enter a value: 1 2 3 Enter b value: a+b=3
Even though we didn’t enter b value, it takes the previously stored value, which is present in buffer already.
In the implementation, when we need to remove standard input buffer data then go for flushall() or fflush() function.
flushall() − It is a predefined function present in stdio.h. by using flushall we can remove the data from I/O buffer.
fflush() − It is a predefined function in "stdio.h" header file which is used to clear either input or output buffer memory.
fflush(stdin) − It is used to clear the input buffer memory. It is recommended to use before writing scanf statement.
fflush(stdout) − It is used for clearing the output buffer memory. It is recommended to use before printf statement.
- Related Questions & Answers
- What do you mean by function return in C language?
- What do you mean by odd loops in C language?
- What do you mean by pointer to a constant in C language?
- What do you mean by C++ Tokens?
- What do you mean by corporate culture?
- What do you mean by compliance specialist?
- What do you mean by Teen Stress?
- What do you mean by performance testing?
- What do you mean by timeOut in TestNG?
- What do you mean by Listeners in TestNG?
- What do you mean by glue in Cucumber?
- What do you mean by schedule in DBMS?
- What do you mean by congestion control algorithm?
- What do you mean by interfaces and services?
- What do you mean by Dynamic memory allocation in C programming?