0% found this document useful (0 votes)
1 views

Chapter 4 Input output statement.doc

Uploaded by

anfalsuriya7333
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1 views

Chapter 4 Input output statement.doc

Uploaded by

anfalsuriya7333
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Chapter 4.

Input\Output statement
The basic operation of every program is to accept the preliminary data from input device (like keyboard),
read this data and perform various operations on it and give desired output to display answers.

In C there is standard input/output library which handles all input and “stdio.h” called as standard
input/output header file. Whenever we use standard input/output function in program, we need to include
this file in program by a statement.

#include <stdio.h>
There are 2 types of input/output statements

1] Formatted input/output statements

2] Unformatted input/output statements

1] Formatted input/output statements

Formatted input/output refers to an input/output data that has been arranged in particular format.

The ‘C’ language supports following formatted statements

1) scanf()
2) printf()

1] scanf() statement :-

Scanf means “scan formatted. This function (statement) reads the data into variable from
keyboard. This statement presents a prompt on the screen and waits for the user to respond by entering
some data and wait for pressing the return key (Enter Button). Whatever the user types is stored in
memory.

Syntax: scanf(“control string , arg1, arg2,…….argn”);

Example : scanf(“%d %f %c”, &I,&f,&char);

The scanf reads until :

a) A whitespace character is found in numeric specification, or

b) Maximum number of characters have been read, or

c) An error is deducted, or d) The end of file is reached.

2] printf() statement :-

The prinf() function is used to print formatted output on the screen. It prints the values of the
variable on screen according to sequence.

Syntax :- printf(“control string”, arg1, arg2, ……., argn);

Control strings consists of 3 types

1. Character that will be printed on the screen as they appear.

2. Format specifications that define the output format for display of each item.
3. Escape sequence characters such as ‘\n’, ‘\t’ and ‘\b’, etc

Example :-

printf(“\n The Addition is %d”, add);

2] Unformatted input/output statements :-

C language supports following types of Unformatted input/output statements.

1> getchar( ) :- Simplest task of all input operations is reading a character from the input device
i.e., keyboard. Reading single character is done by using getchar() function.

The getchar( ) takes the following form.

Variable_name = getchar( );

Example :- char ch;

ch = getchar( );

when this statement is encountered, the computer waits until the key is pressed and assign
this character as a value getchar function and then function assigned this value to the left.

2> putchar( ) :-

There is analogous function putchar( ) for writing character on output device.

The general form of putchar( ) function is as follows :-

Syntax :- putchar (variable_name);

When variable_name is a type char variable containing a character. This statement


displays the character contained in variable_name at the terminal.

Example :- char ch =’Y’;

putchar(ch);

You might also like