Unit 2 - Practice Quiz
CSE101
1
Which of the following statements is true regarding the execution of the if-else statement in C?
else block is executed only when the if condition evaluates to 0.
else block is executed only when the if condition evaluates to 1.
else block is mandatory in every if statement.
2
What is the output of the following code snippet?
c
int a = 10;
if (a = 5)
printf("True");
else
printf("False");
3
Which data types are allowed for the expression in a switch statement in C?
4
What happens if a break statement is omitted in a switch case?
5 Which of the following is an Exit Controlled Loop?
6
What is the minimum number of times a while loop is guaranteed to execute?
7 Consider the mathematical expression: . Which loop structure best represents this summation?
for(i=1; i<=10; i++) S = S + i;
for(i=1; i<10; i++) S = S + i;
while(i<=10) S = S + i; (without initialization)
do { S = S + i; } while(i < 10);
8
What is the purpose of the continue statement?
9
In the following nested loop, when does the break statement stop execution?
c
for(i=0; i<5; i++) {
for(j=0; j<5; j++) {
if(j==2) break;
}
}
10
Which of the following is the correct syntax for a goto label?
label name:
label_name:
:label_name
label-name;
11
What does the return statement do in a function having a void return type?
12
Which formatting code is used to print a double value in scientific notation using printf?
%f
%d
%e
%g
13
What is the return value of the scanf() function?
14 Which function is best suited to read a string containing spaces (e.g., "Hello World") from standard input?
scanf("%s", str);
gets(str);
getch();
putchar(str);
15
What does the printf field width specifier %5d imply when printing the integer 10?
10 followed by 3 spaces.
10.
10.
10 five times.
16 Which of the following is an example of Explicit Type Casting?
float a = 10;
int a = 5.5;
float a = (float)5 / 2;
long a = 100;
17 What is the result of the expression in C when variables are integers?
18 Which type modifier increases the range of values a variable can store by utilizing the sign bit?
short
long
unsigned
signed
19 In structured programming, breaking a large program into smaller, manageable sub-programs is known as:
20
What is the correct format specifier to read a single character using scanf?
%s
%d
%c
%f
21
What is the output of puts("Hello");?
22 Which escape sequence represents a horizontal tab?
\n
\t
\b
\r
23
In a for loop for(init; condition; update), if the condition is left blank, how is it interpreted?
24 What is the "Dangling Else" problem?
else has no matching if.
if an else belongs to in nested structures.
else with a switch statement.
else on a new line.
25
What is the size of a long double in standard C (architecture dependent, but generally)?
26
Which function is defined in <conio.h> (non-standard) to read a character without echoing it to the screen?
getchar()
scanf()
getch()
getche()
27
Consider the following code: int x = 10; float y = x;. What type of conversion is this?
28
Which of the following is true about the default case in a switch statement?
continue statement.
29
How do you print the % symbol using printf?
\%
%%
%
\p
30
What is the correct syntax for a do-while loop?
do { //code } while(condition)
do { //code } while(condition);
while(condition) do { //code };
do while(condition) { //code }
31
What is the output of: printf("%d", 1 ? 2 : 3);?
32 Which loop is generally preferred when the number of iterations is known beforehand?
while
do-while
for
goto
33
In the statement scanf("%d", &a);, what does the & symbol represent?
34
What is the output of printf("%0.2f", 3.14159);?
35 Which statement is used to bypass the conditional check of a loop and jump out immediately?
continue
break
exit
return
36
If int i = 0;, what is the value of i after while(i++ < 3);?
37
Which header file is typically required for standard I/O functions like printf and scanf?
<conio.h>
<stdio.h>
<stdlib.h>
<math.h>
38
Can a switch statement use a float variable as a case label?
39
What is the result of (int)3.99?
40 Which of the following is considered 'unformatted' I/O?
printf()
scanf()
fprintf()
getchar()
41
Which logical operator allows an if statement to execute if at least one of two conditions is true?
&&
||
!
&
42
What is the ASCII range for standard char type (signed)?
43 What happens if you assign a value larger than the maximum range to a variable (Overflow)?
44
What is the role of fflush(stdin)?
45 Which loop structure checks the condition at the 'Top' of the loop?
46 What is the syntax for a block of code (compound statement) in C?
( ... )
[ ... ]
{ ... }
< ... >
47 If you want to read a hexadecimal number input into an integer variable, which format specifier applies?
%d
%o
%x
%h
48
What is the scope of variables declared inside the initialization part of a for loop (C99 standard and later)?
49 Which keyword is used to define a constant variable whose value cannot be changed?
static
const
volatile
immutable
50
In the expression a = b + c * d;, which operation is performed first?