NEW
Font size
WorksheetsMultiple Choice Questions
Total questions: 63
Worksheet time: 32mins
In C, which header file must be included to use the printf function? Choose the best answer.
math.h
stdio.h
string.h
stdlib.h
Which C operator is used for assignment? Select one option.
==
=
+=
->
A do-while loop in C executes the loop body at least once because the condition is evaluated after the body. Which statement best describes when the condition check occurs?
Before entering the loop body on every iteration
After executing the loop body on the first iteration only
After executing the loop body on each iteration
Only when a break statement is encountered
Consider typical 32-bit C implementations. What is the usual size of the int data type?
2 bytes
4 bytes
6 bytes
8 bytes
In C, which operator has the highest precedence among these?
Addition (+)
Parentheses ( )
Logical AND (&&)
Assignment (=)
Which keyword in C is used to declare a named constant that cannot be modified after initialization?
static
const
volatile
extern
Which statement terminates the current loop immediately, skipping any remaining iterations?
continue
break
return
goto
Which header file must be included to use the printf function for standard output?
stdlib.h
stdio.h
string.h
ctype.h
C is best described as which type of programming language?
object-oriented
procedural
functional
logic-based
Which operator is used for simple assignment of a value to a variable in C?
==
=
=>
+=
Which loop in C evaluates its condition before the first iteration?
do-while
while
for (without condition)
goto-based loop
Which loop in C is guaranteed to execute its body at least once?
while
do-while
for
range-based for
Typically on many platforms, what is the size of the int data type in C?
2 bytes
4 bytes
6 bytes
8 bytes
Who is widely recognized as the father of the C programming language?
Ken Thompson
Dennis Ritchie
Bjarne Stroustrup
James Gosling
On a typical 32-bit or 64-bit C implementation used in systems programming courses, what is the usual size of the int data type?
2 bytes
4 bytes
8 bytes
Size varies per element of the array
Considering common C operator precedence, which has the highest precedence among the following?
Addition (+)
Parentheses ( )
Logical AND (&&)
Assignment (=)
Which C keyword is used to declare a read-only named constant at compile time?
static
const
volatile
register
Which statement immediately terminates the nearest enclosing loop when executed in C?
continue
break
return from main
goto to a label inside the loop
In a minimal C program that prints a greeting, which line completes the body to display Hello World? Context: // Print Hello World; int main(){ /* missing line */ return 0; }
puts("Hello World");
printf("Hello World");
print("Hello World");
cout << "Hello World";
Which scanf format string correctly reads a single integer into a variable num? Context: // Input an integer; int num; /* missing line */
scanf("%d", &num);
scanf("%i", num);
scanf("%f", &num);
scanf("%ld", num);
Choose the correct if-condition to check whether variable num is even. Context: // Check even number; int num; /* missing line */
if(num / 2 == 0)
if(num % 2 == 0)
if(num % 2 = 0)
if(num == 2)
Which statement correctly increments integer i by one? Context: // Increment value; int i; /* missing line */
i += 2;
i = i + 0;
i++;
++i;
Complete the print statement exactly as expected in these exercises. Which option matches the function name and string literal syntax?
printf("Hello World");
printf('Hello World');
printf("Hello, World"); // with comma
printff("Hello World");
If num is 6, which condition evaluates to true according to the even-check program?
num % 2 == 0
num % 2 != 0
num / 2 == 3
num & 1 == 1
Which operator is specifically highlighted to increment a value in the exercises?
i--
i++
i+=0
++i--
Choose the correct for-loop header repeated across the section to iterate 5 times.
for(i=0; i<5; i++)
for(i=1; i<=5; i++)
for(i=0; i<=5; i++)
for(i=5; i>0; i--)
Which statement would compile successfully in C to print the text Hello World inside main?
printf("Hello World");
System.out.println("Hello World");
Console.WriteLine("Hello World");
echo "Hello World";
Identify the correct relational test for evenness used throughout the programs.
if(num % 2 == 0)
if(num % 2 >= 0)
if(num / 2 == 0)
if(num & 2 == 0)
Which single-line increment is consistent with Program 4, 9, and 14?
i = i + 2;
i++;
i += 0;
i = ++i;
Program 17 is titled "Input an integer" and has a missing line inside main. Which statement correctly reads an integer into a variable using standard input?
printf("Enter a value");
scanf("%d", #);
for(i=0; i<5; i++)
if(num % 2 == 0)
Program 18 is labeled "Check even number" and has a missing line. Which C conditional expression checks whether num is even?
if(num = 2)
if(num % 2 == 0)
if(num / 2 == 0)
if(num % 2 = 0)
Program 19 is labeled "Increment value" with a missing line. Which statement increments i by one using the increment operator?
i = i + 2;
i = i++;
++num;
i++;
A snippet labeled "Start for loop" has a missing line and the provided answer is for(i=0; i<5; i++). What does i<5 represent in this for loop?
The initialization of the loop variable
The condition that controls how the loop terminates
The increment step applied after each iteration
The variable declaration for i
Program 20 repeats the pattern "Start for loop" with a missing line. Which complete for loop header matches the given answer?
for(i=1; i<=5; i++)
for(i=0; i<5; i++)
for(i=5; i>0; i--)
for(i=0; i<=5; ++i)
Program 21 again asks to "Print Hello World". Which function is used to output text to the console in C?
scanf
gets
printf
puts
Program 22 asks to "Input an integer". Which format specifier correctly reads a decimal integer using scanf?
%c
%f
%d
%s
Program 23 checks an even number. Which operator in C provides the remainder and is used in the even check expression?
/ (division)
* (multiplication)
% (modulus)
+ (addition)
Program 24 increments a value. Which of the following statements uses the post-increment operator?
++i;
i += 1;
i++;
i = i + 1;
Program 25 shows "Start for loop" again. If the loop header is for(i=0; i<5; i++), how many times does the loop body execute?
4 times
5 times
6 times
Until i becomes negative
Program 26 asks to print a greeting. Which is a correct printf call to display exactly Hello World without a newline?
printf("Hello World\n");
printf("Hello World");
printf("Hello World ");
printf("\"Hello World\"");
Program 27 focuses on integer input. Which of the following is the most complete and typical scanf usage to store a value in variable num?
scanf("%d", num);
scanf("%d", &num);
scanf("%d");
scanf("%i", num);
Program 28 checks even numbers using if(num % 2 == 0). If num equals 13, which branch executes?
The if branch executes because 13 % 2 equals 0
The else branch executes because 13 % 2 equals 1
Both branches execute due to short-circuiting
Neither branch executes because the condition is invalid
In C, what is the correct increment operator to increase the value of i by 1 inside a loop? Choose the line that would be placed where a missing increment is required.
i = i + 2;
++i;
i++;
i += 0;
A program comment says: "Start for loop" and variables int num, i; are declared. Which missing line correctly initializes a for loop to iterate 5 times starting at i = 0?
for(i=1; i<=5; i++)
for(i=0; i<5; i++)
for(i=0; i<=4; i--)
for(i=5; i>0; i--)
A program labeled "Print Hello World" requires a single missing line to output text. Which statement correctly prints the string?
printf("Hello World");
scanf("Hello World");
puts(%s, "Hello World");
print("Hello World");
An exercise states: "Input an integer" with int num, i; declared. Which scanf invocation correctly reads an integer into num?
scanf("%f", &num);
scanf("%d", num);
scanf("%d", &num);
scanf("%i", num);
A task says: "Check even number" using int num, i;. Which if condition correctly tests whether num is even?
if(num / 2 == 0)
if(num % 2 == 0)
if(num % 2 = 0)
if(num == 2)
Consider a snippet that declares int num, i; and needs an increment operation after processing each iteration. Which form ensures post-increment of i?
i = i++;
i++;
++i;
i += 2;
For a loop intended to run 5 iterations beginning at i=0, which control expression most closely matches typical C style and prevents off-by-one errors?
for(i=1; i<=5; i++)
for(i=0; i<5; i++)
for(i=0; i<=5; i++)
for(i=5; i>=0; i--)
When the goal is to display the literal Hello World in C, which standard library function and syntax should be used as a single missing line?
printf("Hello World");
cout << "Hello World";
System.out.println("Hello World");
print("Hello World");
A program includes the comment "Input an integer" and has an uninitialized variable num declared as int. What is the correct format string and argument combination to read into num?
scanf("%d", &num);
scanf("%d", num);
scanf("%f", &num);
scanf(num, "%d");
To decide if a number is even in C, which expression is appropriate to place in an if statement’s condition?
(num == 0)
(num / 2 == 1)
(num % 2 == 0)
(num % 2) = 0
A program titled "Increment value" has int num, i; and requires a missing line that increases i by one. Which code line fits best?
i = i + 0;
i = i + 1;
i = ++i;
i = i + 2;
Select the correct for-loop header to perform five iterations starting with i at 0, using a condition that stops before i equals 5.
for(i=0; i<=5; ++i)
for(i=1; i<=5; ++i)
for(i=0; i<5; ++i)
for(i=5; i>=1; --i)
Which single C statement outputs "Hello World" followed by no automatic newline, suitable for filling a one-line print requirement?
printf("Hello World\n");
printf("Hello World");
puts("Hello World");
fprintf(stdout, Hello World);
Given int num, i;, choose the correct scanf call to read one integer from standard input into num using the common decimal format.
scanf("%i", num);
scanf("%d", &num);
scanf("%u", &num);
scanf("%d", &i);
In a C program where variables num and i are declared, which missing line correctly increments the loop counter by one?
i = i + 2;
i++;
++num;
i = i - 1;
Fill the missing line to start a for loop that initializes i to 0 and runs while i is less than 5, incrementing i each iteration.
for(i=1; i<=5; i++)
for(i=0; i<5; i++)
for(i=0; i<=5; i++)
for(i=1; i<5; i++)
Which printf statement correctly prints the exact text Hello World followed by a newline?
printf("Hello World");
printf('Hello World');
printf("Hello World\n");
print("Hello World");
Choose the correct scanf call to read an integer value into the variable num.
scanf("%d", &num);
scanf("%d", num);
scanf("%i", num);
scanf("%f", &num);
Which condition correctly tests whether num is an even integer?
if(num % 2 = 0)
if(num / 2 == 0)
if(num % 2 == 0)
if(num == 2 % 0)
A missing line needs to increment i in a loop within a C program. Which operator provides the most concise increment?
i += 1;
i++;
i = i + 1;
++i;
Select the correct syntax to start a for loop controlling i from 0 up to, but not including, 5.
for(i=0, i<5, i++)
for(i=0; i<5; i++)
for(i=0: i<5: i++)
for(i=0; i<=5; i++)
