I.C.S Part 2 Computer Sciences

Chapter#1          Chapter#10          Chapter#11          Chapter#12


Chapter#10
INPUT/OUTPUT

Output Statement:-
It is a function which is used to get information from the program.
EG: - printf Function
printf Function:-
It is an output function.
It is pronounced as print eff Function.
It is used to display any kind of information on screen.
Its definition is available in stdio.h
printf function can be used in Two ways.
       To Display A message      To Display The Value Of Variable
printf(“Hello World”);                     int age =20;
                                                        printf(“%d”,age)

printf function has Two Parameters.
        1)Format String                            2) List Of Variables

Format String:-
It is represented by pair of double inverted commas (“  ”).
It is the essential parameter of printf function.
Format String Consist of
i. Message
ii. Format Specifier
iii. Escape Sequence

List Of Variables:-
These are the variables whose values are to be displayed on screen.
It is an optical parameter of printf function.
Format Specifier:-
It describes the data type, field width and format specifier of the value.
It always starts with % sign.
Format specifier is used for input/output statements.
It consists of Five Parts.
i. %
ii. Flag
           +
               - 
iii. Precision
iv. Field Width
v. Conversion Character

    % :-
It represents the start of format specifier.
It is a compulsory part of format specifier.
    Flag:-
                    +
It is used to display a number with + sign.
Its used is optional.
                     -
It is used to make justification left aligned.
By default its justification is right aligned.
Its used is optional.
Precision:-
It represents the number of digits after decimal in floating point values.
Its used is optional.
     Field Width:-
It is the number of columns used to represent the value on the screen.
Its used is optional.
Conversion Character:-
It represents format of the value.
It is compulsory part of format specifier.

Q:-What is field width?
ANS:-
1) It is the number of columns used to represent the value on the screen.
2) Each letter, digit, symbol or space represents a single column.
3) Its used is optional.
4) If the value is greater than number of available columns, it will be extended automatically.
5) If numbers of columns are greater than the value to be display, extra columns will be padded.

Escape Sequence:-
These are the characters which are used to control the output on screen.
These characters are not printable.
These characters have different meaning from normal interpretation.
Escape Sequence is always written in format string (“    ”).
Escape Sequence is the combination of Two Characters.
Control Character
Code Character
Control Character:-
Back slash ‘\’ is called control character.
Escape sequence starts with control character.
Code Character:-
Single character after back slash is called code character.
Escape sequence ends with it.
E.g:-
\n                               (Next Line)
\t                                (Tab)
\b                               (Back Space)
\r                                (Carriage Return)

Input Statement:-
This statement is used to provide data to the program.
Input through keyboard is called Standard Input.
There is Two Types of Input.

1. Design Time Input
2. Run-Time Input
      Design Time Input:-
This input is given at the time of writing the program by the programmer.
It is also called Programmer input.
     Run-Time Input:-
This input is given at the time of execution of the program by the user.
It is also called User’s input.
    Run-Time Input Function:-
There is Three Run-Time Input Function.
i. scanf();
ii. getch();
iii. getche();
scanf:-
It is a run-time input function.
It is pronounced as scan-eff function.
Its definition is available in stdio.h
To use this function stdio.h must be include in the source program.
It can take the input of any data type.
Multiple inputs can also be given in one function.
It takes Two Parameters.
1. Format String
2. List Of Addresses Of Variables
Format String:-
It is the first parameter.
It is represented by double inverted commas “   ” .
It contains format specifiers.
List Of Addresses Of Variables:-
& sign is placed before the variable name.
& is called address operator.
If & is omitted before variable name, value will not be located in variable.

    getch Function:-
It is a run-time input function.
It is used to take the input of one character.
Its definition is available in conio.h
It takes no parameter.
It stands for get character.
Entered character is not displayed on screen.

    getche Function:-
It is a run-time input function.
It is used to take the input of one character.
Its definition is available in conio.h
It takes no parameter.
It stands for get character with echo.
Entered character will be displayed on screen.
________________________________________

0 comments:

Post a Comment