Check The Programming Section
Three basic tasks of a program are reading the data through inputs and processing them and writing the data to produce the required output. In a program inputs are taken through input devices such as a keyboard and after processing the data, outputs are displayed into the computer screen. Two ways we can accept the data as follows:
By assigning the values directly to the variables
Accepting the data from input device using input functions
This method is used by the programmer to directly initialize a variable or a constant using an assignment operator. Then this value is directly hard coded by the programmer in the source code. Consider the examples given below:
int a = 23;
char ch = ‘A’;
float avg = 3.5;
Here a, ch, and avg is declared as int, char and float data types and same type constants are assigned to them using an assignment operator. This is also called direct initialisation with declaration.
int a, b;
a = 2 + 3/2 + 4;
b = a + 2;
The above two assignment operations are called indirect or dynamic assignment operations. Because, the value of a is depends on the outcome of the expression specified in the right side of the assignment operator. After that, the value of a is added with 2 and assigned to b.
Another way of taking input using library functions. Library functions are used to take input from the user and after processing them the value gets printed into the computer screen using output functions. These functions are called standard input output functions or in short they also known as standard I/O functions. In C/C++, these standard input functions are further divided into two groups as follows:
Formatted functions
Unformatted functions
These formatted and unformatted functions are defined inside the stdio.h header. The formatted functions can be used with any data types to take input and display the value to the screen. But, unformatted functions are designed to take input and display the output for a particular data type only. Details about these I/O functions are explained in the subsequent sections of this chapter.
Note: The I/O operations are performed as a sequence of bytes called streams. In input operations the bytes means data flows from input device to main memory. Similarly, for output operation data flows from main memory to output devices such as monitor and printer.