C Unit-2 QB
C Unit-2 QB
Unit II
OPERATOR AND EXPRESSIONS
Course Objective – COb 2: To implement programs using basic constructs of C
S.No BTL
Question
. *
1. What is Standard I/O library functions and list 3 processing functions? K1
In C Language input and output function are available as C compiler
functions or C libraries provided with each C compiler implementation.
These all functions are collectively known as Standard I/O Library
function.
Here I/O stands for Input and Output used for different inputting and
outputting statements. These I/O functions are categorized into three
processing functions.
i. Console input/output function
ii. Disk input/output function
iii. Port input/output function
2. What is Console input/output function? K1
All the input/output statements deals with the console, so these are
also Console Input/Output functions. Console Input/Output function
access the three major files before the execution of a C program. They are,
i. Standard input (stdin)
ii. Standard Output (stdout)
iii. Standard Error (stderr)
3. Write about getchar() and putchar() functions. K1
getchar(): It is used for reading a single character from the keyboard. It is a
buffered function. Buffered functions get the input from the keyboard and
store it in the memory buffer temporally until you press the Enter key.
putchar():This function is an output function. It is used to display a single
character on the screen.
Eg. char initial; initial = getchar(); putchar(initial);
4. Define getch(). K1
It is a function is present in conio.h header file. It is used to read a single
character from the keyboard similar to getchar() function. The entered
character is immediately returned without waiting for the enter key. The
entered character does not show up on the console. So it can be used to accept
hidden passwords.
Eg. char pwd; pwd = getchar();
Page|2
Syntax:
if (test expression)
{
Statements;
}
Page|4
14. K3
Write a C program for printing the numbers from 1 to 10 using for loop.
#include <stdio.h>
int main()
{
int i;
for (i = 1; i < 11; ++i)
{
printf("%d ", i);
}
return 0;
}
17. K2
Describe the syntax of for loop.
Syntax:
for (initialize expression; test expression; update expression)
{
body of for loop;
}
while (i <= 5) {
sum = sum + i;
++i;
}
printf("Sum of 1 to 5 = %d", sum);
return 0;
}
19. Differentiate between formatted and unformatted you input and output
functions?
Formatted I/P functions:
These functions allow us to supply the input in a fixed format and let us obtain
the output in the specified form. Formatted output converts the internal binary
representation of the data to ASCII characters which are written to the output K2
file.
Ex: printf, scanf functions
Unformatted I/O functions:
There are several standard library functions available under this category- those
that can deal with a string of characters. Unformatted Input/Output is the most
basic form of input/output. Unformatted input/output transfers the internal
binary representation of the data directly between memory and the file.
Ex: gets,puts, getchar,putchar functions
20. What is the basic difference between for loop and while loop? K2
For loop is used when the number of iterations is known already.
Initialization of iteration variable, test condition and update of the iteration
variable are built-in in the for loop statement.
While loop is used when the number of iterations is not known already. The
iteration variable is initialized before the loop starts, and it is updated in every
iteration of the loop.
21. What are the differences between while loop and do-while loop? K2
WHILE LOOP DO-WHILE LOOP
Entry controlled loop Exit controlled loop
In while-loop, the given condition In do-while-loop, the given body of
is evaluated first and then the body the loop is executed first and then
of the loop is executed. the given condition is checked.
The body of the loop would be The body of the loop would be
executed only if the condition is executed at least once even if the
true. condition is false.
Syntax: Syntax:
while(condition) do
{ {
Body of the loop; Body of the loop;
} } while(condition);
Page|7
Part B
S.No. Question BTL *
1. Explain the various input and output statements in C. K1
What are the different types of operators in C? Discuss each one of them
2. K2
with suitable illustrations.
a) Explain in detail about expressions in C. (8
marks) K2
3. b) What is precedence and order of evaluation? Explain in detail. (8 K2
marks)
4. Explain about decision making statements with suitable examples. K1
Explain switch statement with relevant example. (8
marks) K1
5. Write a C program to design a simple calculator. (8 K3
marks)
Write in detail about the various looping statements available in C with
6. illustrative programs. K2
a) Write a C program to reverse the digits of a number. (8
marks) K3
7. b) Write a C program to display the Fibonacci series. (8 K3
marks)
a) Write a C program to solve a quadratic equation. (8 marks)