stdin
is a term used in C programming language to refer to the standard input stream where data is sent to and read by a program. It is a file descriptor in Unix-like operating systems and programming languages such as C, Perl, and Java. In C programming, stdin
is a predefined file pointer that is automatically opened when a program executes to provide access to the keyboard and screen. It is used to read input from the user via the keyboard or command line. The scanf()
function is commonly used to read input from stdin
. For example, the following code reads a string and an integer from stdin
:
#include <stdio.h>
int main() {
char str[100];
int i;
printf("Enter a string: ");
scanf("%s", str);
printf("Enter an integer: ");
scanf("%d", &i);
printf("You entered: %s %d\n", str, i);
return 0;
}
When the above code is compiled and executed, it waits for the user to input a string and an integer. Whatever is typed is saved in the str
and i
variables and then printed as "You entered: xxxx yyyy," where xxxx
is the string and yyyy
is the integer.