CS Notes Chapter No 3


CHAPTER 3

INPUT AND OUTPUT HANDLING IN C

Q1: What is the use of format specifier? Give examples.

Ans: Format Specifier: Format specifier is a conversion specification code used according to the data type of variable used in input and output function. Format specifier consists of one or more alphabets with % sign. e.g. %d , %c , %f etc.

The most common format specifiers are %d : used with integers %f : used with real numbers %c : used with characters

Q2: Why escape sequences are used? Give example.

Ans: Escape Sequence: These are non-printable characters. These are used to format the output. These are the combination of an alphabet and a mandatory back slash symbol . These can be used everywhere in the string.

The most commonly used escape sequences in C language are following.

n is used for new line

t is used for tab

a is used for beep sound

b is used to delete one character backward etc.

 

Q3: What is the purpose of gets() function?

Ans: Purpose of gets() function: gets() function is used to read a string from keyboard.

Syntax: gets(string);

Where string is a string constant or variable

Q4: Different between getch() and getche() function.

Ans: getch() function: getch() function is an input function, used to read a signal character without an echo. getche() function: getche() function is an input function which reads a character with an echo. We can see the character that is input by getche() function.

Q5: Evaluate the following equations.

  •  9-5*(6+2)

       9-5*8

       9-40

       -31

  •  60/10*24+3

      6*24+3

      144+3

      147

  • 100%50-100%3

      0-100%3

      0-1

      -1