2nd year Chapter 10 Input And Output Question And Answer
Short And Simple Question and Answer
Q 1. What is an input statement?
Ans. An input statement refers to the data or instructions provided to a program through an input device, with the keyboard being a standard input device. In C language, the instructions used to receive input are known as input statements.
Q 2. What is an output statement?
Ans. An output statement is responsible for producing processed input data from a program and sending it to an output device. Typically, the standard output device is the monitor. In C language, built-in functions are used for output, and the instruction used for sending output is referred to as an output statement.
Q 3. What are standard input functions?
Ans. Standard input functions in C include important functions like scanf()
, gets()
, getch()
, and getche()
that are used for receiving input from users.
Q 4. What are standard output functions?
Ans. Standard output functions in C encompass key functions such as printf()
and puts()
that are used to display output.
Q 5. What is the printf()
function?
Ans. The printf()
function is used to display program output on the monitor. It can present text, constants, or variable values in a desired format. It’s considered a formatted output function, part of the C standard library and defined in the stdio.h
header file.
Q 6. What is a format specifier?
Ans. A format specifier is a string used to specify how the value of a variable should be displayed on the monitor. Format specifiers start with a ‘%’ symbol and are used to define the format for displaying values, both for output and input.
Q 7. What is field width in a format specifier?
Ans. Field width, in a format specifier, determines the number of columns used to display a value on the monitor screen. It’s specified by a number in the format specifier and indicates the minimum number of columns to be used for printing a value. It’s optional in the format specifier.
Q 8. What is an escape sequence?
Ans. An escape sequence is a combination of characters used within the printf()
function to control the printing of output. These sequences are not printed and start with a backslash (”). They allow you to include specific characters or control sequences within a string, such as ‘\n’ to represent a new line.
Q 9. What is the getch()
function?
Ans. The getch()
function is used to capture a single character as input from the keyboard. It transfers the typed character to a variable without the need to press the enter key, and the character entered does not appear on the screen.
Q 10. What is the getche()
function?
Ans. The getche()
function is used to obtain a single character as input from the keyboard. Like getch()
, it transfers the character to a variable without requiring the user to press the enter key, and the character is not displayed on the screen.
Q 11. What is the function of the ‘\n’ escape sequence?
Ans. The ‘\n’ escape sequence represents a new line in a string. When encountered in a printf()
statement, it moves the cursor to the beginning of the next line, effectively starting a new line in the output.
Q 12. What is the function of the ‘\t’ escape sequence?
Ans. The ‘\t’ escape sequence represents a horizontal tab. It is used to move the cursor one tab forward from the current position. For example:
printf(“Hello\tPakistan“);
The output of the above statement will be “Hello Pakistan,” with multiple spaces added to align text to the next tab stop.