wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

Multiple Choice Questions

Total questions: 63

Worksheet time: 32mins

Name
Class
Date
1.

In C, which header file must be included to use the printf function? Choose the best answer.

a)

math.h

b)

stdio.h

c)

string.h

d)

stdlib.h

2.

Which C operator is used for assignment? Select one option.

a)

==

b)

=

c)

+=

d)

->

3.

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?

a)

Before entering the loop body on every iteration

b)

After executing the loop body on the first iteration only

c)

After executing the loop body on each iteration

d)

Only when a break statement is encountered

4.

Consider typical 32-bit C implementations. What is the usual size of the int data type?

a)

2 bytes

b)

4 bytes

c)

6 bytes

d)

8 bytes

5.

In C, which operator has the highest precedence among these?

a)

Addition (+)

b)

Parentheses ( )

c)

Logical AND (&&)

d)

Assignment (=)

6.

Which keyword in C is used to declare a named constant that cannot be modified after initialization?

a)

static

b)

const

c)

volatile

d)

extern

7.

Which statement terminates the current loop immediately, skipping any remaining iterations?

a)

continue

b)

break

c)

return

d)

goto

8.

Which header file must be included to use the printf function for standard output?

a)

stdlib.h

b)

stdio.h

c)

string.h

d)

ctype.h

9.

C is best described as which type of programming language?

a)

object-oriented

b)

procedural

c)

functional

d)

logic-based

10.

Which operator is used for simple assignment of a value to a variable in C?

a)

==

b)

=

c)

=>

d)

+=

11.

Which loop in C evaluates its condition before the first iteration?

a)

do-while

b)

while

c)

for (without condition)

d)

goto-based loop

12.

Which loop in C is guaranteed to execute its body at least once?

a)

while

b)

do-while

c)

for

d)

range-based for

13.

Typically on many platforms, what is the size of the int data type in C?

a)

2 bytes

b)

4 bytes

c)

6 bytes

d)

8 bytes

14.

Who is widely recognized as the father of the C programming language?

a)

Ken Thompson

b)

Dennis Ritchie

c)

Bjarne Stroustrup

d)

James Gosling

15.

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?

a)

2 bytes

b)

4 bytes

c)

8 bytes

d)

Size varies per element of the array

16.

Considering common C operator precedence, which has the highest precedence among the following?

a)

Addition (+)

b)

Parentheses ( )

c)

Logical AND (&&)

d)

Assignment (=)

17.

Which C keyword is used to declare a read-only named constant at compile time?

a)

static

b)

const

c)

volatile

d)

register

18.

Which statement immediately terminates the nearest enclosing loop when executed in C?

a)

continue

b)

break

c)

return from main

d)

goto to a label inside the loop

19.

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; }

a)

puts("Hello World");

b)

printf("Hello World");

c)

print("Hello World");

d)

cout << "Hello World";

20.

Which scanf format string correctly reads a single integer into a variable num? Context: // Input an integer; int num; /* missing line */

a)

scanf("%d", &num);

b)

scanf("%i", num);

c)

scanf("%f", &num);

d)

scanf("%ld", num);

21.

Choose the correct if-condition to check whether variable num is even. Context: // Check even number; int num; /* missing line */

a)

if(num / 2 == 0)

b)

if(num % 2 == 0)

c)

if(num % 2 = 0)

d)

if(num == 2)

22.

Which statement correctly increments integer i by one? Context: // Increment value; int i; /* missing line */

a)

i += 2;

b)

i = i + 0;

c)

i++;

d)

++i;

23.

Complete the print statement exactly as expected in these exercises. Which option matches the function name and string literal syntax?

a)

printf("Hello World");

b)

printf('Hello World');

c)

printf("Hello, World"); // with comma

d)

printff("Hello World");

24.

If num is 6, which condition evaluates to true according to the even-check program?

a)

num % 2 == 0

b)

num % 2 != 0

c)

num / 2 == 3

d)

num & 1 == 1

25.

Which operator is specifically highlighted to increment a value in the exercises?

a)

i--

b)

i++

c)

i+=0

d)

++i--

26.

Choose the correct for-loop header repeated across the section to iterate 5 times.

a)

for(i=0; i<5; i++)

b)

for(i=1; i<=5; i++)

c)

for(i=0; i<=5; i++)

d)

for(i=5; i>0; i--)

27.

Which statement would compile successfully in C to print the text Hello World inside main?

a)

printf("Hello World");

b)

System.out.println("Hello World");

c)

Console.WriteLine("Hello World");

d)

echo "Hello World";

28.

Identify the correct relational test for evenness used throughout the programs.

a)

if(num % 2 == 0)

b)

if(num % 2 >= 0)

c)

if(num / 2 == 0)

d)

if(num & 2 == 0)

29.

Which single-line increment is consistent with Program 4, 9, and 14?

a)

i = i + 2;

b)

i++;

c)

i += 0;

d)

i = ++i;

30.

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?

a)

printf("Enter a value");

b)

scanf("%d", #);

c)

for(i=0; i<5; i++)

d)

if(num % 2 == 0)

31.

Program 18 is labeled "Check even number" and has a missing line. Which C conditional expression checks whether num is even?

a)

if(num = 2)

b)

if(num % 2 == 0)

c)

if(num / 2 == 0)

d)

if(num % 2 = 0)

32.

Program 19 is labeled "Increment value" with a missing line. Which statement increments i by one using the increment operator?

a)

i = i + 2;

b)

i = i++;

c)

++num;

d)

i++;

33.

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?

a)

The initialization of the loop variable

b)

The condition that controls how the loop terminates

c)

The increment step applied after each iteration

d)

The variable declaration for i

34.

Program 20 repeats the pattern "Start for loop" with a missing line. Which complete for loop header matches the given answer?

a)

for(i=1; i<=5; i++)

b)

for(i=0; i<5; i++)

c)

for(i=5; i>0; i--)

d)

for(i=0; i<=5; ++i)

35.

Program 21 again asks to "Print Hello World". Which function is used to output text to the console in C?

a)

scanf

b)

gets

c)

printf

d)

puts

36.

Program 22 asks to "Input an integer". Which format specifier correctly reads a decimal integer using scanf?

a)

%c

b)

%f

c)

%d

d)

%s

37.

Program 23 checks an even number. Which operator in C provides the remainder and is used in the even check expression?

a)

/ (division)

b)

* (multiplication)

c)

% (modulus)

d)

+ (addition)

38.

Program 24 increments a value. Which of the following statements uses the post-increment operator?

a)

++i;

b)

i += 1;

c)

i++;

d)

i = i + 1;

39.

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?

a)

4 times

b)

5 times

c)

6 times

d)

Until i becomes negative

40.

Program 26 asks to print a greeting. Which is a correct printf call to display exactly Hello World without a newline?

a)

printf("Hello World\n");

b)

printf("Hello World");

c)

printf("Hello World ");

d)

printf("\"Hello World\"");

41.

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?

a)

scanf("%d", num);

b)

scanf("%d", &num);

c)

scanf("%d");

d)

scanf("%i", num);

42.

Program 28 checks even numbers using if(num % 2 == 0). If num equals 13, which branch executes?

a)

The if branch executes because 13 % 2 equals 0

b)

The else branch executes because 13 % 2 equals 1

c)

Both branches execute due to short-circuiting

d)

Neither branch executes because the condition is invalid

43.

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.

a)

i = i + 2;

b)

++i;

c)

i++;

d)

i += 0;

44.

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?

a)

for(i=1; i<=5; i++)

b)

for(i=0; i<5; i++)

c)

for(i=0; i<=4; i--)

d)

for(i=5; i>0; i--)

45.

A program labeled "Print Hello World" requires a single missing line to output text. Which statement correctly prints the string?

a)

printf("Hello World");

b)

scanf("Hello World");

c)

puts(%s, "Hello World");

d)

print("Hello World");

46.

An exercise states: "Input an integer" with int num, i; declared. Which scanf invocation correctly reads an integer into num?

a)

scanf("%f", &num);

b)

scanf("%d", num);

c)

scanf("%d", &num);

d)

scanf("%i", num);

47.

A task says: "Check even number" using int num, i;. Which if condition correctly tests whether num is even?

a)

if(num / 2 == 0)

b)

if(num % 2 == 0)

c)

if(num % 2 = 0)

d)

if(num == 2)

48.

Consider a snippet that declares int num, i; and needs an increment operation after processing each iteration. Which form ensures post-increment of i?

a)

i = i++;

b)

i++;

c)

++i;

d)

i += 2;

49.

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?

a)

for(i=1; i<=5; i++)

b)

for(i=0; i<5; i++)

c)

for(i=0; i<=5; i++)

d)

for(i=5; i>=0; i--)

50.

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?

a)

printf("Hello World");

b)

cout << "Hello World";

c)

System.out.println("Hello World");

d)

print("Hello World");

51.

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?

a)

scanf("%d", &num);

b)

scanf("%d", num);

c)

scanf("%f", &num);

d)

scanf(num, "%d");

52.

To decide if a number is even in C, which expression is appropriate to place in an if statement’s condition?

a)

(num == 0)

b)

(num / 2 == 1)

c)

(num % 2 == 0)

d)

(num % 2) = 0

53.

A program titled "Increment value" has int num, i; and requires a missing line that increases i by one. Which code line fits best?

a)

i = i + 0;

b)

i = i + 1;

c)

i = ++i;

d)

i = i + 2;

54.

Select the correct for-loop header to perform five iterations starting with i at 0, using a condition that stops before i equals 5.

a)

for(i=0; i<=5; ++i)

b)

for(i=1; i<=5; ++i)

c)

for(i=0; i<5; ++i)

d)

for(i=5; i>=1; --i)

55.

Which single C statement outputs "Hello World" followed by no automatic newline, suitable for filling a one-line print requirement?

a)

printf("Hello World\n");

b)

printf("Hello World");

c)

puts("Hello World");

d)

fprintf(stdout, Hello World);

56.

Given int num, i;, choose the correct scanf call to read one integer from standard input into num using the common decimal format.

a)

scanf("%i", num);

b)

scanf("%d", &num);

c)

scanf("%u", &num);

d)

scanf("%d", &i);

57.

In a C program where variables num and i are declared, which missing line correctly increments the loop counter by one?

a)

i = i + 2;

b)

i++;

c)

++num;

d)

i = i - 1;

58.

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.

a)

for(i=1; i<=5; i++)

b)

for(i=0; i<5; i++)

c)

for(i=0; i<=5; i++)

d)

for(i=1; i<5; i++)

59.

Which printf statement correctly prints the exact text Hello World followed by a newline?

a)

printf("Hello World");

b)

printf('Hello World');

c)

printf("Hello World\n");

d)

print("Hello World");

60.

Choose the correct scanf call to read an integer value into the variable num.

a)

scanf("%d", &num);

b)

scanf("%d", num);

c)

scanf("%i", num);

d)

scanf("%f", &num);

61.

Which condition correctly tests whether num is an even integer?

a)

if(num % 2 = 0)

b)

if(num / 2 == 0)

c)

if(num % 2 == 0)

d)

if(num == 2 % 0)

62.

A missing line needs to increment i in a loop within a C program. Which operator provides the most concise increment?

a)

i += 1;

b)

i++;

c)

i = i + 1;

d)

++i;

63.

Select the correct syntax to start a for loop controlling i from 0 up to, but not including, 5.

a)

for(i=0, i<5, i++)

b)

for(i=0; i<5; i++)

c)

for(i=0: i<5: i++)

d)

for(i=0; i<=5; i++)