0% found this document useful (0 votes)
21 views2 pages

Io Statements in C

Uploaded by

Dhavan Ravuri
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views2 pages

Io Statements in C

Uploaded by

Dhavan Ravuri
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

Input and Output statements:

Input statements:
* Input is information supplied to program.
* Input statement is used to take input from user.
* It will take data from user and stores in a variable.
* C supports the following input statements
1.scanf( )
2.getc( )
3.getchar( )
4.getch( )

scanf( ):
* It is a standard input statement in C
* Used to take any type of data from user.
* The following syntax is used to write scanf( ) in program.

syntax:
scanf("formatspecifier",&variablename,....);
formatspecifier:
* It indicates what type of data user must enter as input.
* "%" is used to represent format specifier.
datatype formatspecifer
char %c
int %d
short %i
long %ld
float %f
double %lf
long double %llf

&variablename:
* Every variable has name and address.
* To know the variable address we have to use &(Ampersand)
* & is also called address operator(Reference operator)

ex:
int x;
scanf("%d",&x);
float y;
scanf("%f",&y);
char c;
scanf("%c",&c);
int a,b;
scanf("%d",&a);
scanf("%d",&b);
double z;
char d;
scanf("%lf",&z);
scanf("%c",&d);

getc( ) / getchar( )/getch( ):


* Used to read character data from stdout(Screen/console)
syntax:
variablename=getc( );
variablename=getchar( );
variablename=getch( );
* getch( ) -> will read data directly from input device (not from STDOUT)
ex:
char gender;
gender=getc( );

Output statement:
* The results produced by a program on screen are called as output.
* Output statements are used display output on screen.
* C supports the following output statements
1.printf( )
2.putc( )
3.putchar( )
1.printf( ):
* It is a standard output statement
* Used to display all formats of information.
syntax:
printf("Message");
* message will be displayed as it is.
example:
printf("W-e-l-c-o-m-e");
output:
W-e-l-c-o-m-e
syntax:
* printf( ) is also used display data stored in variable
printf("Formatspecifier",variablename,....);
exmaple:
int x=20;
printf("%d",x);
float y=23.343;
printf("%f",y);

putc( )/ putchar( ):
* used to display only character type of data.
syntax:
putc(variablename);
putchar(variablename);
example:
char gender='m';
putc(gender);
putchar(gender);

You might also like