Notice: Due to an ongoing migration of our storage and publishing system, material requested since last month will not be uploaded for the time being, and new requests are paused. All existing notes remain available.
Question 1 of 60 · introduction of control statement · Easy
What is the main purpose of control statements in C?
Not quite. Try another option.
Answer: To control the flow of execution of a program
Control statements decide the order in which statements of a program are executed, allowing branching and looping.
Question 2 of 60 · introduction of control statement · Easy
Which of the following is NOT a category of control statements in C?
Not quite. Try another option.
Answer: Declaration statements
Control statements are categorized into selection, iteration, and jump statements. Declaration is not a control statement category.
Question 3 of 60 · condition statements · Easy
Conditional statements in C execute a block of code based on the result of a:
Not quite. Try another option.
Answer: Boolean (true/false) condition
Conditional statements evaluate an expression as true or false and execute code accordingly.
Question 4 of 60 · if · Easy
In an if statement, the block of code executes only when the condition is:
Not quite. Try another option.
Answer: True (non-zero)
The body of an if statement runs only when its condition evaluates to a non-zero (true) value.
Question 5 of 60 · if · Easy
What is the output of the following code?
c
int x = 5;
if (x > 3)
printf("Yes");
Not quite. Try another option.
Answer: Yes
Since is true, the printf statement executes and prints Yes.
Question 6 of 60 · if-else · Easy
In an if-else statement, the else block executes when the condition is:
Not quite. Try another option.
Answer: False
The else block runs only when the if condition evaluates to false (zero).
Question 7 of 60 · if-else · Easy
What is the output of the following code?
c
int a = 2;
if (a == 5)
printf("Equal");
else
printf("Not Equal");
Not quite. Try another option.
Answer: Not Equal
Since a is 2, the condition a == 5 is false, so the else block runs and prints Not Equal.
Question 8 of 60 · nested if and switch statement · Easy
A nested if statement means:
Not quite. Try another option.
Answer: An if statement inside another if statement
Nesting means placing one if statement within the body of another if or else block.
Question 9 of 60 · nested if and switch statement · Easy
Which keyword is used to define the default case in a switch statement?
Not quite. Try another option.
Answer: default
The default label handles all cases not matched by any case value in a switch statement.
Question 10 of 60 · nested if and switch statement · Easy
What happens if break is omitted after a matching case in a switch statement?
Not quite. Try another option.
Answer: Execution falls through to the following cases
Without break, control continues (falls through) into the subsequent case statements until a break or the end of the switch.
Question 11 of 60 · nested if and switch statement · Easy
The expression used in a switch statement must evaluate to which type of value?
Not quite. Try another option.
Answer: An integer or character constant
A switch expression must result in an integral value (int or char); floats and strings are not allowed.
Question 12 of 60 · looping statements-while and do-while loop · Easy
In a while loop, when is the condition checked?
Not quite. Try another option.
Answer: Before each iteration of the loop body
A while loop is entry-controlled: the condition is tested before the body executes each time.
Question 13 of 60 · looping statements-while and do-while loop · Easy
How many times is the body of a do-while loop guaranteed to execute at minimum?
Not quite. Try another option.
Answer: At least once
A do-while loop is exit-controlled, so its body runs once before the condition is checked.
Question 14 of 60 · looping statements-while and do-while loop · Easy
Which loop checks its condition at the end (bottom) of the loop?
Not quite. Try another option.
Answer: do-while loop
The do-while loop is exit-controlled and evaluates its condition after executing the body.
Question 15 of 60 · looping statements-while and do-while loop · Easy
What is the output of the following code?
c
int i = 1;
while (i <= 3) {
printf("%d", i);
i++;
}
Not quite. Try another option.
Answer: 123
The loop prints i while , incrementing each time, so it prints 1, 2, then 3.
Question 16 of 60 · for loop · Easy
In a for loop, which part is executed only once, at the very beginning?
Not quite. Try another option.
Answer: Initialization
The initialization expression in a for loop runs a single time before the loop starts.
Question 17 of 60 · for loop · Easy
How many times will the following loop print Hi?
c
for (int i = 0; i < 4; i++)
printf("Hi");
Not quite. Try another option.
Answer: 4 times
The loop runs for , which is 4 iterations, so Hi prints 4 times.
Question 18 of 60 · break and continue statements · Easy
What does the break statement do inside a loop?
Not quite. Try another option.
Answer: Terminates the loop immediately
The break statement exits the loop entirely and transfers control to the statement after the loop.
Question 19 of 60 · break and continue statements · Easy
What does the continue statement do inside a loop?
Not quite. Try another option.
Answer: Skips the rest of the current iteration and moves to the next
The continue statement skips the remaining statements in the current iteration and jumps to the next iteration.
Question 20 of 60 · goto statement · Easy
The goto statement transfers control to a:
Not quite. Try another option.
Answer: Labeled statement in the program
The goto statement performs an unconditional jump to a labeled statement within the same function.
Question 21 of 60 · introduction of control statement · Medium
Which category of control statements is used to repeatedly execute a block of code based on a condition?
Not quite. Try another option.
Answer: Iteration statements
Iteration (looping) statements like while, do-while, and for repeatedly execute a block of code as long as a condition holds true.
Question 22 of 60 · condition statements · Medium
What is the value of the expression 5 > 3 && 2 < 1 in C?
Not quite. Try another option.
Answer:
5 > 3 is true (1), but 2 < 1 is false (0). Logical AND of true and false yields false, which is in C.
Question 23 of 60 · if · Medium
What does the following code print?
C
int x = 10;
if (x = 5)
printf("Yes");
else
printf("No");
Not quite. Try another option.
Answer: Yes
x = 5 is an assignment, not a comparison. It assigns 5 to x and the expression evaluates to 5 (non-zero, true), so Yes is printed.
Question 24 of 60 · if-else · Medium
What is the output of the following code?
C
int a = 7;
if (a % 2 == 0)
printf("Even");
else
printf("Odd");
Not quite. Try another option.
Answer: Odd
7 % 2 equals 1, so a % 2 == 0 is false. The else branch executes, printing Odd.
Question 25 of 60 · nested if and switch statement · Medium
In the code below, which else does the inner if associate with?
C
if (a > 0)
if (b > 0)
printf("A");
else
printf("B");
Not quite. Try another option.
Answer: The inner if (b > 0)
In C, an else always binds to the nearest unmatched if. Here the else pairs with the inner if (b > 0), regardless of indentation.
Question 26 of 60 · nested if and switch statement · Medium
What is the output of the following switch statement?
C
int n = 2;
switch (n) {
case 1: printf("One");
case 2: printf("Two");
case 3: printf("Three");
default: printf("None");
}
Not quite. Try another option.
Answer: TwoThreeNone
There are no break statements, so execution falls through from case 2 onward, printing Two, Three, and None.
Question 27 of 60 · nested if and switch statement · Medium
Which data type is NOT allowed as a switch expression in C?
Not quite. Try another option.
Answer: float
A switch expression must evaluate to an integral type. float (and double) are not permitted; int, char, and enum are all valid.
Question 28 of 60 · looping statements-while and do-while loop · Medium
How many times does the body of this loop execute?
C
int i = 5;
while (i < 5) {
printf("%d", i);
i++;
}
Not quite. Try another option.
Answer: times
The condition i < 5 is checked first and is false (5 < 5 is false), so the while loop body never executes.
Question 29 of 60 · looping statements-while and do-while loop · Medium
How many times does the body of this loop execute?
C
int i = 5;
do {
printf("%d", i);
i++;
} while (i < 5);
Not quite. Try another option.
Answer: time
A do-while loop checks the condition after the body, so the body runs at least once before i < 5 (6 < 5) fails.
Question 30 of 60 · looping statements-while and do-while loop · Medium
What is the final value printed by this code?
C
int sum = 0, i = 1;
while (i <= 4) {
sum += i;
i++;
}
printf("%d", sum);
Not quite. Try another option.
Answer:
The loop adds to sum as i runs from 1 to 4.
Question 31 of 60 · for loop · Medium
What is the output of the following code?
C
for (int i = 0; i < 3; i++)
printf("%d ", i * i);
Not quite. Try another option.
Answer: 0 1 4
As i takes values 0, 1, 2, the printed squares are , , and respectively.
Question 32 of 60 · for loop · Medium
How many times does the following loop execute?
C
for (int i = 10; i > 0; i -= 3)
printf("*");
Not quite. Try another option.
Answer: times
i takes values 10, 7, 4, 1 (all > 0), then becomes -2 and stops. That is 4 iterations.
Question 33 of 60 · for loop · Medium
What happens when all three expressions of a for loop are omitted, as in for(;;)?
Not quite. Try another option.
Answer: It creates an infinite loop
With no condition present, the for loop condition is treated as always true, producing an infinite loop unless broken internally.
Question 34 of 60 · break and continue statements · Medium
What is the output of the following code?
C
for (int i = 1; i <= 5; i++) {
if (i == 3)
break;
printf("%d ", i);
}
Not quite. Try another option.
Answer: 1 2
When i reaches 3, break exits the loop immediately, so only 1 and 2 are printed.
Question 35 of 60 · break and continue statements · Medium
What is the output of the following code?
C
for (int i = 1; i <= 5; i++) {
if (i % 2 == 0)
continue;
printf("%d ", i);
}
Not quite. Try another option.
Answer: 1 3 5
continue skips the rest of the body for even values of i, so only odd numbers 1, 3, and 5 are printed.
Question 36 of 60 · break and continue statements · Medium
In nested loops, what does a break statement inside the inner loop terminate?
Not quite. Try another option.
Answer: Only the inner loop
break terminates only the loop in which it directly appears. Control then returns to the enclosing outer loop.
Question 37 of 60 · goto statement · Medium
What is the output of the following code?
C
int i = 0;
start:
printf("%d ", i);
i++;
if (i < 3)
goto start;
Not quite. Try another option.
Answer: 0 1 2
The goto jumps back to start while i < 3, printing 0, 1, and 2 before the condition becomes false.
Question 38 of 60 · goto statement · Medium
Which statement about the goto statement in C is correct?
Not quite. Try another option.
Answer: It transfers control to a labeled statement within the same function
goto performs an unconditional jump to a label, but that label must reside within the same function; it cannot cross function boundaries.
Question 39 of 60 · if-else · Medium
What is the output of this ternary-based code?
C
int a = 4, b = 9;
int max = (a > b) ? a : b;
printf("%d", max);
Not quite. Try another option.
Answer:
The conditional operator evaluates a > b (4 > 9) as false, so it returns b, which is .
Question 40 of 60 · for loop · Medium
What is the output of the following nested loop?
C
for (int i = 1; i <= 2; i++)
for (int j = 1; j <= 2; j++)
printf("%d%d ", i, j);
Not quite. Try another option.
Answer: 11 12 21 22
For each i (1, 2), the inner loop runs j from 1 to 2, producing the pairs 11, 12, 21, and 22.
Question 41 of 60 · if-else · Hard
What is the output of the following code?
C
#include <stdio.h>
int main() {
int a = 5, b = 10;
if (a > b)
if (a > 0)
printf("X");
else
printf("Y");
return 0;
}
Not quite. Try another option.
Answer: Prints nothing
The dangling else binds to the nearest unmatched if, i.e. if (a > 0). Since a > b (5 > 10) is false, the outer if body never executes, so neither X nor Y is printed.
Question 42 of 60 · switch statement · Hard
What does this program print?
C
#include <stdio.h>
int main() {
int x = 2;
switch (x) {
case 1: printf("1");
case 2: printf("2");
case 3: printf("3"); break;
default: printf("D");
}
return 0;
}
Not quite. Try another option.
Answer: 23
Execution jumps to case 2 and, without a break, falls through to case 3, printing 2 then 3. The break in case 3 stops further fall-through, so the output is 23.
Question 43 of 60 · for loop · Hard
What is the output of the following code?
C
#include <stdio.h>
int main() {
int i, sum = 0;
for (i = 1; i <= 10; i++) {
if (i % 2 == 0) continue;
if (i > 7) break;
sum += i;
}
printf("%d", sum);
return 0;
}
Not quite. Try another option.
Answer: 16
Even values are skipped by continue. Odd values processed: 1, 3, 5, 7 are added (). At the break fires before adding. So the sum is .
Question 44 of 60 · looping statements-while and do-while loop · Hard
What is printed by this code?
C
#include <stdio.h>
int main() {
int i = 5;
do {
printf("%d ", i);
i -= 2;
} while (i > 0);
return 0;
}
Not quite. Try another option.
Answer: 5 3 1
A do-while runs the body first. It prints 5 (), 3 (), 1 (). After printing 1, the condition is false, so the loop stops. Output: 5 3 1.
Question 45 of 60 · for loop · Hard
What is the output?
C
#include <stdio.h>
int main() {
int i;
for (i = 0; i < 5; i++);
printf("%d", i);
return 0;
}
Not quite. Try another option.
Answer: 5
The semicolon right after the for header makes an empty loop body. The loop runs until , then the printf (which is not part of the loop) executes once, printing 5.
Question 46 of 60 · nested if · Hard
For which value of n does this print Match?
C
if (n > 0) {
if (n % 3 == 0) {
if (n % 2 != 0)
printf("Match");
}
}
Not quite. Try another option.
Answer: n = 9
All three conditions must hold: positive, divisible by 3, and odd. Only satisfies all three (, , ). and are even; is not positive.
Question 47 of 60 · goto statement · Hard
What is the output of this code?
C
#include <stdio.h>
int main() {
int i = 0, sum = 0;
loop:
i++;
if (i == 3) goto skip;
sum += i;
skip:
if (i < 5) goto loop;
printf("%d", sum);
return 0;
}
Not quite. Try another option.
Answer: 12
The loop runs for . When , goto skip bypasses sum += i. So sum = .
Question 48 of 60 · break and continue statements · Hard
What is the output of the nested loop?
C
#include <stdio.h>
int main() {
int i, j, c = 0;
for (i = 1; i <= 3; i++) {
for (j = 1; j <= 3; j++) {
if (j == 2) break;
c++;
}
}
printf("%d", c);
return 0;
}
Not quite. Try another option.
Answer: 3
break only exits the inner loop. For each of the 3 outer iterations, the inner loop increments c once (at ) then breaks at . So .
Question 49 of 60 · switch statement · Hard
What does the following print?
C
#include <stdio.h>
int main() {
int x = 1, y = 0;
switch (x) {
case 1: y += 1;
case 2: y += 2;
default: y += 10;
case 3: y += 3;
}
printf("%d", y);
return 0;
}
Not quite. Try another option.
Answer: 16
Matching case 1 with no breaks causes fall-through through every subsequent label regardless of order: . default runs because it lies in the fall-through path.
Question 50 of 60 · for loop · Hard
What is the output?
C
#include <stdio.h>
int main() {
int i, j;
for (i = 0, j = 10; i < j; i++, j--)
;
printf("%d %d", i, j);
return 0;
}
Not quite. Try another option.
Answer: 5 5
Both i and j change each iteration. They meet when : after iterations with (0,10),(1,9),(2,8),(3,7),(4,6) the update yields (5,5), where is false. So output is 5 5.
Question 51 of 60 · looping statements-while and do-while loop · Hard
What is the output of this program?
C
#include <stdio.h>
int main() {
int i = 1;
while (i <= 100) {
i *= 2;
}
printf("%d", i);
return 0;
}
Not quite. Try another option.
Answer: 128
i doubles: 2, 4, 8, 16, 32, 64, 128. At , is true so it becomes 128. Then is false, loop ends. Final value printed is 128.
Question 52 of 60 · if-else · Hard
What does this print for the assignment shown?
C
#include <stdio.h>
int main() {
int a = 3, b = 5;
int max = (a > b) ? a : (b > 10 ? b : a + b);
printf("%d", max);
return 0;
}
Not quite. Try another option.
Answer: 8
First (3>5) is false, so evaluate the second ternary. (5>10) is false, so the result is .
Question 53 of 60 · break and continue statements · Hard
What is the output?
C
#include <stdio.h>
int main() {
int i = 0;
while (i < 5) {
i++;
if (i == 3) continue;
printf("%d", i);
}
return 0;
}
Not quite. Try another option.
Answer: 1245
i is incremented before the check, so values 1..5 are considered. When , continue skips the printf. All others print, giving 1245. Note the increment happens before continue, avoiding an infinite loop.
Question 54 of 60 · switch statement · Hard
Which statement about this code is correct?
C
int x = 2;
switch (x) {
case 1.5: printf("A"); break;
case 2: printf("B"); break;
}
Not quite. Try another option.
Answer: Compilation error: case label is not an integer constant
In C, switch case labels must be integer constant expressions. case 1.5: uses a floating-point value, which is illegal and causes a compilation error.
Question 55 of 60 · for loop · Hard
What is the output of this code?
C
#include <stdio.h>
int main() {
int count = 0;
for (int i = 1; i <= 3; i++)
for (int j = i; j <= 3; j++)
count++;
printf("%d", count);
return 0;
}
Not quite. Try another option.
Answer: 6
Inner iterations: for , (3 times); , (2 times); , (1 time). Total .
Question 56 of 60 · nested if · Hard
What is printed?
C
#include <stdio.h>
int main() {
int a = 0;
if (a = 5)
if (a == 5)
printf("P");
else
printf("Q");
else
printf("R");
return 0;
}
Not quite. Try another option.
Answer: P
a = 5 is an assignment yielding 5 (non-zero, true), so the outer if executes. Inside, a == 5 is true, printing P. The else clauses are not reached.
Question 57 of 60 · looping statements-while and do-while loop · Hard
How many times does the body execute?
C
int i = 10;
while (i-- > 0) {
// body
}
Not quite. Try another option.
Answer: 11
The post-decrement i-- returns the current value then decrements. The condition is true for (10 times) and also when (returns 0? no). Actually it tests values 10 down to 1 as true and then i=0 returns 0 which is false—wait, i-- > 0 uses the pre-decrement value: it is true while the returned value is 1..10, that's 10 true tests, plus the final test returns 0 (false). Body runs 10 times... re-check: values returned are 10,9,...,1,0; the first 10 are >0 (true), so body runs 10 times. The 11th test returns 0 and stops. Correct count is 10.
Question 58 of 60 · goto statement · Hard
What does this code output?
C
#include <stdio.h>
int main() {
int i = 1;
start:
if (i <= 3) {
printf("%d", i);
i++;
goto start;
}
printf("End");
return 0;
}
Not quite. Try another option.
Answer: 123End
The goto start simulates a loop. It prints 1, 2, 3 (incrementing each time), then when the condition fails and it prints End. Output: 123End.
Question 59 of 60 · condition statements · Hard
What is the output?
C
#include <stdio.h>
int main() {
int x = 5, y = 5, z;
z = x++ || ++y;
printf("%d %d %d", x, y, z);
return 0;
}
Not quite. Try another option.
Answer: 6 5 1
In x++ || ++y, x++ evaluates to 5 (non-zero, true), then x becomes 6. Because || short-circuits on a true left operand, ++y is never evaluated, so y stays 5. The logical result z is 1.
Question 60 of 60 · introduction of control statement · Hard
Which classification correctly groups these C control statements?
Answer: Group 1: selection, Group 2: iteration, Group 3: jump
C control statements fall into three categories: selection (decision-making: if, if-else, switch), iteration (looping: while, do-while, for), and jump (unconditional transfer: break, continue, goto, return).
That's unit 3
Answer a few questions and your score shows up here.
Nearly through. Did unit 3 of CAP1008 save you a night before the exam?
LPU Notes is free. A student pays for the servers.
Did unit 3 of CAP1008 save you a night before the exam?
Then you can help keep it free for the next batch. Ads cover part of the server bill;
the rest comes out of a student's own pocket: the domain, the storage, and keeping
the site up through the weeks everyone needs it at once.
The payment button didn't load. An ad blocker or a filtered network is the usual reason.
to try again.