DigiBacc

Practice questionsIB Computer ScienceProgramming
IB Computer Science

Programming practice questions.

99 exam-style questions on Programming with answers and explanations. Six real samples below — the full set is free with an account.

Syllabus

Topics covered

Try it

Sample questions

A booking system must store a customer telephone number that begins with a zero and is never used in a calculation. Which data type is the most suitable?

  • Integer
  • Real
  • String
  • Boolean

Answer: String

Stored as a number the leading zero would be lost and no arithmetic is ever wanted on the value, so the digits are held as characters. A telephone number looks numeric but behaves like text.

Which value is stored in TOTAL by the statement in the listing?

  • 33
  • 23
  • 90
  • 14

Answer: 23

Multiplication is carried out before addition, so 6 * 3 = 18 is worked out first and TOTAL becomes 5 + 18 = 23. Working strictly left to right gives (5 + 6) * 3 = 33, which is the commonest slip; 90 multiplies everything and 14 adds everything.

A cinema gives a discount to a customer who is a member and under 18, and also to any customer aged 65 or over. Which of the conditions in the listing selects exactly those customers?

  • Condition A
  • Condition B
  • Condition C
  • Condition D

Answer: Condition C

Only C makes membership a requirement for the under-18s while leaving the over-65s free of it; A demands an age of 65 or over from every customer, so no member under 18 can qualify and the under-18 alternative inside its brackets is dead. B wrongly demands membership from every customer aged 65 or over, and the bracket in D asks for an age that is both under 18 and at least 65, which is never true, so D simply gives the discount to any member of any age.

A variable is created inside a subprogram and its value is not passed back to the calling code. Which statement about that variable is correct?

  • It keeps its value between separate calls of the subprogram
  • It can be read by any other subprogram in the program
  • It must be given the same name as the value returned
  • It exists only while the subprogram is running

Answer: It exists only while the subprogram is running

A local variable is created when the subprogram is entered and destroyed when it ends, so nothing outside can reach it and nothing survives to the next call. That is exactly why the same identifier may be reused safely elsewhere.

A whole number of items is typed at the keyboard and arrives in the variable ENTRY as text. The program must add that number to a running total. What must happen before the addition can be carried out?

  • ENTRY must be converted to an integer
  • The running total must be converted to text
  • ENTRY must be stored as a Boolean value
  • The running total must be rounded to a whole number

Answer: ENTRY must be converted to an integer

Arithmetic needs a numeric type, so the characters have to be converted to an integer before they can be added; joining text to text would only place the digits side by side. Converting the running total to text instead would lose the arithmetic altogether.

The table shows the two-dimensional array GRID. Row indices run down the left-hand side and column indices across the top, and both start at 0. Which expression selects the value 8?

  • GRID[2][1]
  • GRID[0][2]
  • GRID[1][2]
  • GRID[2][2]

Answer: GRID[1][2]

The first index always names the row and the second the column, so 8 sits in row 1, column 2. GRID[2][1] reverses the two indices and lands on 3, which is the commonest slip once a grid is no longer square.

99 Programming questions — free with an account. Spaced repetition, streaks and full exam simulations included.

Practise them free
All subjects Pricing For teachers

This platform is independently developed and is not endorsed by, affiliated with, or sponsored by the International Baccalaureate Organization. “International Baccalaureate” and “IB” are registered trademarks of the IBO.