Programming Concepts

Practice questions

Which search method halves the range on each step?

  1. Linear search
  2. Binary search
  3. Random search
  4. Serial search
Answer and explanation

Answer: B

Binary search divides a sorted list in half at every comparison.

A class is best described as:

  1. A blueprint for objects
  2. A running program copy
  3. A name for a variable
  4. A kind of program loop
Answer and explanation

Answer: A

A class is a blueprint or template from which objects are made.

Which structure is first in, first out?

  1. Stack
  2. Array
  3. Queue
  4. Tree
Answer and explanation

Answer: C

A queue removes the item that arrived first.

A program runs to the end but prints a wrong answer. This is a

  1. Syntax error
  2. Runtime error
  3. Compile-time error
  4. Logical error
Answer and explanation

Answer: D

Wrong results from a program that runs normally indicate a logical error.

Which translator executes a program statement by statement?

  1. Compiler
  2. Assembler
  3. Interpreter
  4. Preprocessor
Answer and explanation

Answer: C

An interpreter translates and runs one statement at a time.

Which number is a palindrome?

  1. 1223
  2. 1231
  3. 1212
  4. 1221
Answer and explanation

Answer: D

1221 reads the same forwards and backwards.

The digit sum of 7305 is

  1. 12
  2. 15
  3. 10
  4. 20
Answer and explanation

Answer: B

7 + 3 + 0 + 5 = 15.

Which of these numbers is prime?

  1. 53
  2. 57
  3. 49
  4. 51
Answer and explanation

Answer: A

51 = 3 x 17, 57 = 3 x 19 and 49 = 7 x 7; 53 has no divisor from 2 to 7, so it is prime.

What is the factorial of 5?

  1. 25
  2. 210
  3. 120
  4. 240
Answer and explanation

Answer: C

1 x 2 x 3 x 4 x 5 = 120.

Which operator gives the last digit of a whole number n?

  1. n / 10
  2. n * 10
  3. n % 10
  4. n - 10
Answer and explanation

Answer: C

The remainder after dividing by 10 is the last digit.

x = 4; x = x * 3; x = x - 5. What is x?

  1. 7
  2. 12
  3. 5
  4. 9
Answer and explanation

Answer: A

x becomes 12 and then 12 - 5 = 7.

Evaluate (3 > 1) AND (2 > 5).

  1. True
  2. Error
  3. Unknown
  4. False
Answer and explanation

Answer: D

The second comparison is false, so True AND False is False.

Evaluate 4 + 18 / 3 % 4.

  1. 5
  2. 8
  3. 6
  4. 4
Answer and explanation

Answer: C

18 / 3 = 6, then 6 % 4 = 2, then 4 + 2 = 6.

What is 23 % 6?

  1. 4
  2. 5
  3. 3
  4. 2
Answer and explanation

Answer: B

23 = 6 x 3 + 5, so the remainder is 5.

Evaluate 12 / 4 * 3.

  1. 9
  2. 1
  3. 3
  4. 36
Answer and explanation

Answer: A

Work left to right: 12 / 4 = 3, then 3 * 3 = 9.

A loop is written with the test after the body. A body that prints 'Hi' with an initially false test prints it how many times?

  1. For ever
  2. Never
  3. Twice
  4. Once
Answer and explanation

Answer: D

A loop that tests after the body, such as DO-WHILE, always runs once.

n = 20; count = 0; WHILE n > 0: n = n - 6; count = count + 1. What is count?

  1. 3
  2. 4
  3. 6
  4. 5
Answer and explanation

Answer: B

n takes 14, 8, 2 and -4. That is 4 subtractions, so count = 4.

S = 0; FOR i = 1 TO 5: S = S + i * 2. What is S?

  1. 30
  2. 15
  3. 10
  4. 25
Answer and explanation

Answer: A

2 x (1 + 2 + 3 + 4 + 5) = 2 x 15 = 30.

x = 2; WHILE x < 50: x = x * 2. What is x when the loop ends?

  1. 32
  2. 64
  3. 50
  4. 100
Answer and explanation

Answer: B

x takes 2, 4, 8, 16, 32 and then 64. 64 is not less than 50, so the loop stops with x = 64.

How many times does FOR i = 3 TO 11 run its body?

  1. 8
  2. 10
  3. 9
  4. 11
Answer and explanation

Answer: C

The count is 11 - 3 + 1 = 9.

Privacy · Terms · Refunds · Delivery