Blogger templates

Pages

Friday, 20 April 2012

What Is scanf() and printf() Function

C functions

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:
  1. printf()
  2. scanf()
  3. gets()
  4. puts()
  5. getch()
  6. getchar()
  7. putchar()
  8. getche()

Mainly there are two types of input-output(I/O) statements:
  1. Formatted I/O statements
  2. 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. 
The syntax of scanf() :


  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.

NOTE: The character f in the scanf() shows the format(" ") of this function.

Printf() Function:
  • It is used to display the data on the monitor. 
  • It is included in the stdio.h header file. 
The syntax of printf() is:


  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.

NOTE: The character f in the printf() shows the format(" ") of this function

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.
Example:  
#include<stdio.h>
where  #include is a preprocessor directive and <stdio.h> is a header file.


0 comments:

Post a Comment