INPUT AND OUTPUT HANDLING CH# 03
Questions and Answers
Short Questions
i.
Why
format specifier is used? Explain with examples.
Ans: Format
Specifier:
A format specifier is computer code that
tells about the data type, field width and the format according to which a
value is to be read or printed. Commonly used format specifiers are;
i.
%d decimal integer
ii.
%i integer
iii.
%f floating-point
➤➤➤➤➤➤➤➤➤➤➤➤
ii.
Why escape sequence is used? Explain with
examples.
Ans: Escape Sequence:
The special characters used in C language to
control printing on the output device are called escape sequence. These
characters are not printed, and used inside the control string.
It is a combination of a backslash(\) and a
code character. Commonly used escape sequence are;
i.
\a produces alert (bell) sound.
ii.
\b moves cursor backward.
iii.
\n moves cursor to the beginning of next
line.
➤➤➤➤➤➤➤➤➤➤➤➤
iii. What is the purpose of gets() function? Explain with an example.
Ans: gets() Function:
The gets() function is used to read a string from the
keyboard and store it in the variable specified inside the parenthesis.
Example:
#include<stdio.h>
void main (void)
{
char name[20];
printf(“\nEnter your name:”);
gets(name);
printf(“\nMy name is %s”,name);
getch();
}
➤➤➤➤➤➤➤➤➤➤➤➤
iv.
Differentiate between getch( ) and getche( ) functions.
Ans: getch() Function:
The getch() is similar to getche(), the
difference is that it does not display the typed character to the screen. The
function require conio.h header file.
getche() Function:
The getche() reads a single character from
the keyboard and it is assigned to the variable. The format specifier %c print
the letter stored in variable. The ‘get’ means get something from input device.
The ‘ch’ means it get a character and ‘e’ means it echoes (display) the
character to the screen.
➤➤➤➤➤➤➤➤➤➤➤➤
Fbise Notes-Computer | Input and Output Handling Short Questions Ch.No3
Reviewed by fbisenotes
on
July 23, 2019
Rating:
No comments: