Unit 2 - Practice Quiz
CSE109
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
%d
%c
%f
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?
break
goto
return
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?
scanf()
printf()
gets()
fprintf()
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
jump
goto
move
10
What is the return type of the printf() function?
void
int
char *
float
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
long
signed
unsigned
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?
printf()
puts()
putchar()
fprintf()
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?
%f
%d
%e
%g
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?
<conio.h>
<stdlib.h>
<stdio.h>
<string.h>
25
What happens if the condition in a while loop is initially false?
26 Which of the following best describes structured programming?
goto statements extensively
main function
27
What is the size modifier to print a long double?
%f
%lf
%Lf
%ld
28 Which statement allows skipping the current pass in a loop but continuing with the next?
break
stop
continue
exit
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
gets()
getchar()
32
The return statement is used to:
33 What is the correct syntax for a ternary operator?
condition ? expression1 : expression2
condition : expression1 ? expression2
condition ? expression1 ; expression2
expression1 ? expression2 : condition
34
In the format string "%5d", what does the 5 represent?
35 Which of the following is NOT a looping structure in C?
for
while
repeat-until
do-while
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?
\s
\t
\b
\n
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?
scanf("%s", str)
gets(str)
getchar()
getch()
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?
int
long
size_t
float
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;
short int i;
signed void v;
50
The exit() function is used to: