In UNIX, all input and output is done by reading or writing files, because all peripheral devices (including keyboard and screen) are files in the file system. This means a single homogeneous interface handles all communication between a program and peripheral devices.
A non-negative integer is used to refer to the file (analogous to the file pointer we saw earlier used by the standard library) and this is called file descriptor. All information about an open file is maintained by the system; the user program refers to the file only by the file descriptor.
When running a program via the shell (terminal), three files are open with file descriptors 0 (standard input), 1 (standard output) and 2 (standard error).
On the command-line, we can redirect input and output using < and >.
./a.out < input > output
In this case, the shell changes the default assignments for file descriptors 0 and 1 to the named files.