Output/Input in C

C language does not provide facility for input and output operation. The input and output is performed through a set of library function that are supplied with C compiler. The set of library function that performed input and output operations is called standard I/O library.

In C program, the scanf ( ) library function  is used for input and the printf ( ) library function is used for output.

Reading input data

Input data can be entered into memory from standard input device.The scanf ( ) library function used for entering input data. Scanf ( ) function take all types of values (number, character, string) as input.

The scanf ( ) function written as:-

Scanf ("control string", address 1, address 2,......);

In scanf ( ) function, control string contains conversion character enclosed within double quotes. The conversion specification may one or more it depend on the number of variable. The addresses is a variable address.The address of variable is found by preceding variable name by (&) sign. This sign is called address operator and it gives the starting address of the variable name in memory.

Example of scanf () function

int main (void)
int marks;
scanf ("%d", &marks);

In this example, the control string contains one conversion character %d, which implies that one integer entered as input. This entered value will be stored in the variable marks.

Writing output data

Output data can be written from computer memory to the standard output device. The printf ( ) library function is used for written output data. printf ( ) function take all types value (number, character, string) as output.

The printf ( ) function written as:-

printf ("control string", variable 1, variable 2,.....);

In printf ( ) function, the control string contains conversion character and text enclosed within double quotes. If the control string does not contain any conversion character, the variable names are specified.

Example of printf ( ) function

int main (void)
printf ("c is execllent\n");
return 0;

In this example, the control string has only text and no conversion character, so the output is only text.

Character I/O

The getchar ( ) and putchar ( ) function is used for character I/O. getchar ( ) function reads a single character from the standard input. putchar ( ) out one character at a time to the standard output. 

Leave a Reply