Various I/O Statements used in ‘C’ language


Various Statements used in ‘C’ language:
I / O Statements:
            An I/O statement is related to the operations to the performed on I/O device.  There are two types I/O functions are used frequently in ‘c’ language. They are ‘printf’  and ‘scanf’.
These two functions are available in the header file ‘stdio.h’.
printf: This function is used to display the information on the screen .
It is a precompiled library function in ‘C’ language prototyped in ‘stdio.h’.
The syntax of printf is
printf(“string / formatted string / escape sequences”, value 1, value 2,…);
 printf statement displays the information available in the string as usual. If it is a formatted character such as %d or %c etc the value corresponding to it substituted. If we use an escape sequence character the meaning is changed.
Example :  printf( “Welcome to C”);    à welcome to C
                  printf(“%d”, 4*20)            à 80
                  printf(“%o”,40)                 à 050
                 printf (“%d”,’A’)               à 65


 
 

Scanf:  It is an input function which is used to read information from keyboard into a memory location (address of a variable).
It is a precompiled library function in ‘C’ language prototyped in stdio.h.
The syntax of scanf is as  follows:
Scanf(“formatted string”,&u1,&u2,…);
            To specify the address of a variable   we can use operator ampersand (&) which stands for address of.
            We can use scanf function in a ‘c’ program  we have to use only formatted characters no others are not allowed.
Example :  int a,b;
                        Float    c;
                        longdouble   d;
            scanf(“%d%d%f%lf”,&a,&b,&c,&d);
Conversion specifications that we need presently are as follows
%d    àinteger representation
%f     à float representation
%c    à character representation
%u    àunsigned integer or address representation
%s     à  String representation




Followers