Lesson 4.1.1.6

4.1.1.6 Constants and variables Quiz: AQA Computer Science, Unit 1

20 questions

In partnership with Revision Ninja

Lesson 4.1.1.6, Constants and variables: 20 multiple choice questions for the AQA Computer Science (7517), Unit 1: Fundamentals of programming, written with Revision Ninja.

Host it live on the board and students join with a game code on their own devices, or revise alone with Free Play. The answers are revealed in the game.

Host this setFree Play

The 20 questions

  1. What is the key difference between a variable and a constant?

    • A variable's value can change while the program runs, but a constant's value cannot
    • A constant is stored in a file on disk, while a variable is never saved to any file
    • A constant's value can change while the program runs, but a variable's value cannot change once set
    • A variable must hold a number, while a constant may hold any type of data such as text
  2. What is the main advantage of using a named constant instead of a literal value?

    • The value can be changed in one place when the rule changes
    • The value no longer needs a data type
    • The program runs faster because the value is cached
    • It allows the value to change while running
  3. Which statement describes a constant?

    • A value that is recalculated on each loop iteration
    • A named value that is fixed once it has been declared
    • A value entered by the user at runtime
    • A memory address stored in a pointer
  4. What does an assignment statement do?

    • Compares two values and returns TRUE or FALSE
    • Stores a value in a variable
    • Calls a subroutine by its name
    • Defines a new data type
  5. Which name follows common convention for a named constant that holds the number of days in a week?

    • daysInWeekCount
    • 7 days in a week
    • DaysInWeekTotalValue
    • DAYS_IN_WEEK
  6. A program reads a constant TAX_RATE and a variable price. Which statement is correct?

    • TAX_RATE can be reassigned, but price cannot
    • Neither can be used in a calculation
    • price can be reassigned, but TAX_RATE cannot
    • Both can be reassigned at any time
  7. What is the purpose of initialising a variable before its first use?

    • So the variable can be shared with an external file without being declared in the code
    • So the variable does not need a data type because its value is known from the start
    • So the variable is automatically converted into a constant for the rest of the program
    • So it starts with a known value rather than an unpredictable one
  8. CONST MAX = 10 is declared, and the code later uses MAX * 2. What is the value?

    • 20
    • 10
    • 5
    • 12
  9. x := 5, then x := x + 3. What is the final value of x?

    • 8
    • 15
    • 3
    • 5
  10. A constant GST_RATE = 0.2 is applied to a price of 50 to find the tax. What is the tax?

    • 15
    • 250
    • 5
    • 10
  11. A program tries to assign a new value to a named constant after it has been declared. What usually happens?

    • The constant is copied to a new memory address and kept
    • The assignment is rejected as an error
    • The constant becomes a variable for the rest of the program
    • The new value silently replaces the constant
  12. To swap the values of variables a and b, which sequence of statements works correctly?

    • a := b; b := a; temp := a
    • temp := a; a := b; b := temp
    • temp := b; a := a; b := temp
    • a := a + b; b := a; temp := b
  13. A variable count is set to 0 and incremented once inside a loop that runs 4 times. What is count at the end?

    • 3
    • 5
    • 0
    • 4
  14. Which identifier is most meaningful for storing the number of students enrolled on a course?

    • numberOfStudents
    • x1, a valid name that says nothing about the value it holds
    • t, a single letter that is often reused for several different values
    • n, a single letter that gives no clue about the value it holds
  15. A program stores the maximum number of players as a named constant, with the value 8. Why is this helpful if the rule might change later?

    • Changing a constant automatically changes all other variables
    • The program will not need to be recompiled
    • The number can be changed by the players during play
    • Only the declaration needs editing rather than every use of the number
  16. A total variable is initialised to 0. Then 5 is added three times and 2 is subtracted once. What is the final total?

    • 3
    • 10
    • 15
    • 13
  17. A constant RATE = 0.05 is applied as compound interest to a balance of 100 for 2 years. What is the balance at the end, to 2 decimal places?

    • 110.00
    • 105.00
    • 110.25
    • 115.50
  18. A program hardcodes the value 25 in six places. The value must change to 30. What is the best approach to avoid six separate edits?

    • Replace the literal with a named constant and change its declaration
    • Store 25 in a Boolean variable instead, so that the value is changed from TRUE to FALSE only
    • Edit each literal separately in every place it appears, checking each one by hand for mistakes
    • Remove all six uses and rely on a default value that the language assigns to every number
  19. A running total is not reset to 0 before a second run of the same calculation. What is the likely effect on the second result?

    • It becomes a constant
    • It is automatically reset by the language
    • It is always zero
    • It includes values left over from the first run
  20. Which is the best justification for declaring a constant PI = 3.14159 rather than using the literal 3.14159 throughout a program?

    • It allows the value to be changed by the user while the program is running, for flexibility
    • It documents the meaning of the value and keeps a single place to change it
    • It makes the program run faster than the literal because the value is cached by the processor
    • It converts the value to an integer automatically, so the decimal places are lost

All AQA Computer Science quizzes