Unit 2 - Practice Quiz
1
Which of the following is the correct syntax for a switch statement expression in C?
2
What is the minimum number of times a do-while loop is guaranteed to execute?
3
Which format specifier is used to read a single character in scanf()?
%s
%c
%f
%d
4
What is the output of the following C code fragment?
c
int a = 5;
if (a = 0) {
printf("True");
} else {
printf("False");
}
5 Which jump statement is used to immediately terminate the current iteration of a loop and proceed to the next iteration?
return
break
goto
continue
6
What does the break statement do when used inside a nested loop?
7 Which of the following is an example of an unformatted input function?
fprintf()
gets()
printf()
scanf()
8
What is the result of the expression (float)5 / 2?
9 Which keyword is used to transfer control to a specific label within the same function?
switch
goto
jump
move
10
What is the return type of the printf() function?
float
char *
int
void
11
In the syntax for(initialization; condition; increment/decrement), which part is optional?
12
What is the role of the default case in a switch statement?
13 Which type modifier allows a variable to store only positive integers?
short
unsigned
long
signed
14
What is the purpose of the & operator in scanf("%d", &a)?
15
What is the output of the following?
int i = 0; while(i < 3) { printf("%d ", i); i++; }
16
Which of the following functions appends a newline character \n automatically at the end of the output?
putchar()
fprintf()
puts()
printf()
17
What happens if a break statement is omitted in a switch case?
18 Which format specifier is used to print a floating-point number in scientific notation?
%g
%f
%d
%e
19 Implicit type conversion is also known as:
20 Which logic structure fits the description: 'Execute a block of code repeatedly as long as a condition is true, checking the condition before execution'?
do-while
while
switch
if-else
21
What is the output of printf("%%d");?
d
%d
22 Which of the following creates a block scope in C?
{}
[]
()
<>
23
If x = 5, what is the value of x after x += x + 5?
24
Which header file is generally required for printf and scanf?
<stdio.h>
<stdlib.h>
<string.h>
<conio.h>
25
What happens if the condition in a while loop is initially false?
26 Which of the following best describes structured programming?
main function
goto statements extensively
27
What is the size modifier to print a long double?
%Lf
%f
%lf
%ld
28 Which statement allows skipping the current pass in a loop but continuing with the next?
break
exit
continue
stop
29
In a switch statement, can two cases have the same value?
30
What is the result of 3 << 2?
31 Which function is unsafe to use because it does not check the buffer size?
fgets()
scanf() with width
getchar()
gets()
32
The return statement is used to:
33 What is the correct syntax for a ternary operator?
condition ? expression1 : expression2
expression1 ? expression2 : condition
condition ? expression1 ; expression2
condition : expression1 ? expression2
34
In the format string "%5d", what does the 5 represent?
35 Which of the following is NOT a looping structure in C?
while
do-while
repeat-until
for
36
What is the output of printf("%.2f", 3.14159);?
37
When defining a variable long int, which keyword can be omitted?
long
int
long or int
38
Which of the following statements about goto is true?
39
What does putchar(c) do?
c
c
c to stdout
c into memory
40
If int a = 10;, what is the value of a after printf("%d", a++); executes?
41 Which escape sequence represents a tab space?
\n
\t
\b
\s
42 What happens if you assign a float value to an int variable?
43
In a for loop, when is the initialization expression executed?
44 Which function allows reading a string with spaces?
getchar()
getch()
gets(str)
scanf("%s", str)
45
What is the correct way to output a double quote character " using printf?
\q
\"
%'
"
46 Short-circuit evaluation means:
47
Which data type is the result of sizeof operator?
size_t
float
long
int
48
What is the output of int x=1; switch(x) { case 1: printf("1"); case 2: printf("2"); }?
49 Which of the following is a valid variable declaration using a type modifier?
unsigned float x;
long char c;
signed void v;
short int i;
50
The exit() function is used to: