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.
The 20 questions
-
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
-
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
-
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
-
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
-
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
-
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
-
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
-
CONST MAX = 10 is declared, and the code later uses MAX * 2. What is the value?
- 20
- 10
- 5
- 12
-
x := 5, then x := x + 3. What is the final value of x?
- 8
- 15
- 3
- 5
-
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
-
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
-
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
-
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
-
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
-
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
-
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
-
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
-
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
-
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
-
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
Related quizzes
- Data types Quiz · 4.1.1.1 · 20 questions
- Programming concepts: sequence, selection and iteration Quiz · 4.1.1.2 · 20 questions
- Arithmetic operations Quiz · 4.1.1.3 · 20 questions
- Relational and Boolean operations Quiz · 4.1.1.4 · 20 questions
- String-handling operations Quiz · 4.1.1.7 · 20 questions
- Random numbers and exception handling Quiz · 4.1.1.8 · 20 questions
- Subroutines Quiz · 4.1.1.10 · 20 questions
- Parameters and returning values Quiz · 4.1.1.11 · 20 questions
- Local and global variables Quiz · 4.1.1.13 · 20 questions
- Stack frames in subroutine calls Quiz · 4.1.1.15 · 20 questions