C language use of a buffer
C uses a buffer to output or input variables. The buffer stores the variable that is supposed to be taken in (input) or sent
Code
The following code takes multiple characters in the variables v1 and v2. However, the first character is stored in the variable, while the next character is stored in the operating system’s buffer.”
Sample input: a b c
Stored in variable v1: a
Stored in buffer: b c
Stored in v2: b
#include<stdio.h>#include<conio.h>
void main()
{
int v1,v2;
clrscr();
printf("\n Enter v1: ");
scanf("%d",&v1);
printf("\n Enter v2: ");
scanf("%d",&v2);
printf("\n v1+v2=%d ",v1+v2);
getch();
}
Output
Enter v1: 10
Output
Enter v1: 10
Enter v2: 20
v1+v2=30
Run the program again
Enter v1: 10 20 30
Enter v2: (nothing)
v1+v2=30
v2 is automatically taken from the previous run by the buffer.