Additional Question Answers

Q: Why are I/O functions needed?

We need a way to provide input and show output while writing programs. Each programming language has its own keywords or standard library functions for I/O operations. C language offers printf function to display and scanf function to get input from users.

Q: Write down the output of the following code:

# include <stdio.h>

void main ()

{

  printf (“I am UPPERCASE and I am lowercase”);

}

Output:

I am UPPERCASE and I am lowercase

Q: How can we display the value of a variable?

If we want to display the value of a variable then it is must to add relevant format specifiers where the value is shown and also mentioning the variable name at the end of printf statement inside the round braces. e.g. printf ("My age is %d and my height is %f", age, height);

Q: While using float data type how can we specify the number to be shown after decimal point?

When we use %f to display a float value, it displays 6 digits after decimal point. If we want to specify the number of digits after decimal point then we can write %.nf where n is the number of digits. e.g. printf ("My age is %d and my height is %.2f", age, height);

Q: Why is %i format specifier used?

For datatype integer we use %d as well as %i as a format specifier.

Q: How scanf statements written? / Write the syntax of scanf statement. / Write the name of the two parts of scanf statement/function.

There are 2 main parts of scanf functions. First part inside the double quotes is the list of format specifiers and second part is the list of variables with & sign at their left.

Q: Can we take multiple inputs through single scanf statement?

We can take multiple inputs using single scanf statement/function e.g. look at the following statement:

scanf ("%d%d%f", &a, &b, &c);

It takes two integer type variables and one float type variable.

Q: What happens if & sign is not added in scanf functions?

It is a very common mistake to forget & sign in the scanf functions. Without & sign, the program gets executed but does not behave as expected.

Q: Which library is needed for adding getch() function?

To use getch() function, we need to include the library conio.h in the header section of the program.

Q: What is statement terminator?

A statement terminator is identifier for compiler which identifies end of line. In C language ; semicolon is used as statement terminator.

Q: Write the purpose of escape sequence?

Escape sequences are used in printf functions inside the ” ” and they force printf to change its normal behavior of showing output.

Q: Why do we use \n and \t?

\n is an escape sequence which is used to print the output on multiple lines. While \t specifies the I/O function of moving to the next tab stop horizontally. The tab stop is collection of 8 spaces.

Q: What happens in the absence of escape sequence?

In the absence of an escape sequence, even if we have multiple printf statements, their output is displayed on a single line.

Q: How to write a statement in C to increase or decrease the value of variable by 1?

The statement a = a+1; is used to increase the value of variable a by 1. In C language, this statement can also be written as a++ or ++a;

Similarly, --a or a--; to decrease the value of variable by 1.