C is a functional programming language. C provides library of functions to perform input-output operations. This library is called a standard input-output library. It is denoted by stdio. The header file containing such library functions is called stdio.h. Some standard input-output functions in C are:
- printf()
- scanf()
- gets()
- puts()
- getch()
- getchar()
- putchar()
- getche()
Mainly there are two types of input-output(I/O) statements:
- Formatted I/O statements
- Unformatted I/O statements
scanf() and printf() are formatted input and output statements where as getchar(), gets() and putchar(),puts() are unformatted input and output statements.
Lets have a look on Two most widely used INPUT and OUTPUT Functions:
Scanf() Function:
- To read the values for the variables in a program from the keyboard , C provides a function called scanf().
- It is equivalent to the READ statement.
- It is included in stdio.h header file.
scanf(" control string" , address_list ); |
Where
Control string => It is asequence of one or more character group. Each character group is a combination of the % symbol and one of the conversion character. Control string specifies the type of the values which are to be supplied to the variable.
Address_list => Address of the memory location where the value of the input variables should be stored.
Printf() Function:
- It is used to display the data on the monitor.
- It is included in the stdio.h header file.
printf("Control string" , variable); |
Control string => this specifies the type and format of the values to be displayed.
Variable => list of variables to be displayed.
Header files:
- Files that are placed before main() of a C program are called header files.
- The header files are used to provide necessary information.
- Header files contain library functions.
- They can be written with in the angle brackets or the double quotes.
- The header files usually contains .h as extension.
- They are entered into the source program via #include directive.
Preprocessor directive:
- C processor is a collection of special statements are called preprocessor directive.
- It is executed before the C program is complied.
- The preprocessor directive begin with the # symbol and followed by either the include or define keyword.
- They are used to include files into a program.
#include<stdio.h>
where #include is a preprocessor directive and <stdio.h> is a header file.
0 Response to "What Is scanf() and printf() Function"
Post a Comment