Header Ads Widget

Input - Output in C

The input - output is performed through set of library functions , that are supplied with every C compiler. If a program uses any function from standard input /output library, then it should include the header file <stdio.h> .

Conversion specification character : scanf() and printf()  make use of conversion specification character to specify the the type and size of data . It must begin with % .
Ex.          %d  for integer
                %c  for single character constant
                %s  for string

Reading input data :
scanf( ) library function

scanf( " Control String", address 1, address 2, ..... ,address n);

scanf() should have at least two parameters :- 1) Control string    2) Address . Control string contains conversion specification character . It should be written within double quotes. Conversion specification character may be one or more . It depends on number of values we want to input but at least one address should be present. Address of variable is found by preceding the variable by an  & sign. & is address of operator which gives starting address of variable name in memory. It should be noted that a sting variable is not preceded by an &.

 void main( )
{
int z;
..........
scanf( " %d", &z); 
..........................
..........................
}

Writing output  data :
printf( ) library function

printf( " Control String", variable 1, variable 2, ..... ,variable n);

Control string contains conversion specification character or text or both. If the control string does not contain any conversion specification,then variable names are not specified . The name of variable should not be preceded by an & sign.


#include <stdio.h>
void main( )
{
int a;
printf("Enter Number :  \n");
scanf( "%d", &a);
printf(" Number = %d",a);
}

Post a Comment

2 Comments

  1. I wondered upon your blog and wanted to say that I have really enjoyed reading your blog posts. Anyway, I’ll be subscribing to your feed and I hope you post again soon.Python Online Training
    Learn Python Online

    ReplyDelete