AP Computer Science A Practice Quiz: Variables and Data Types
Written by AP Content Team, Verified for 2026 AP Exams, Last updated: May 2026
Test your understanding with short quizzes. This quiz has 14 questions to check your progress.
Question 1 of 14
All Questions (14)
A) To perform a set of operations on values.
B) To define a category of data, such as numbers or Booleans.
C) To store a value that can change while the program is running.
D) To represent a constant, unchanging value throughout the program.
Correct Answer: C
The provided content states, 'A variable is a storage location that holds a value, which can change while the program is running.'
A) int
B) double
C) boolean
D) reference
Correct Answer: A
The number of students is a whole number, which is an integer. The content specifies that 'An int value is an integer.'
A) int
B) double
C) boolean
D) primitive
Correct Answer: B
An average grade with a decimal point is a real number. The content states, 'A double value is a real number.'
A) int
B) double
C) boolean
D) reference
Correct Answer: C
This scenario represents a choice between two states (accepted or not accepted), which corresponds to the 'true' or 'false' values of the boolean data type.
A) A value and an operation
B) A name and an associated data type
C) A data type and a primitive value
D) A name and a storage location
Correct Answer: B
The content explicitly states, 'Every variable has a name and an associated data type.'
A) int age;
B) double age;
C) age int;
D) boolean age;
Correct Answer: A
This demonstrates the correct syntax for declaring a variable. 'int' is the appropriate data type for a whole number age, and 'age' is the variable name.
A) int isGameOver;
B) isGameOver boolean;
C) double isGameOver;
D) boolean isGameOver;
Correct Answer: D
The state of the game being over is either true or false, which requires the 'boolean' data type. The syntax 'boolean isGameOver;' correctly declares the variable.
A) A storage location that holds a value.
B) A name associated with a value in memory.
C) A value that is either true or false.
D) A set of values and a corresponding set of operations on those values.
Correct Answer: D
This is the direct definition provided in the content: 'A data type is a set of values and a corresponding set of operations on those values.'
A) int
B) double
C) boolean
D) reference
Correct Answer: A
These are all integers (whole numbers). The content specifies that 'An int value is an integer.'
A) A data type
B) A primitive value
C) A variable name
D) An operation
Correct Answer: C
In a variable declaration, the data type (`double`) is followed by the name of the variable (`accountBalance`). The variable is the storage location itself.
A) The variable name `itemCount` is invalid.
B) The number of items must be a real number.
C) The number of items is a whole number, so `int` is more appropriate.
D) `double` is a reference type and cannot be used for numbers.
Correct Answer: C
You cannot have a fraction of an item in a cart; the count must be an integer. While a `double` could store a whole number (e.g., 5.0), the `int` data type is the most precise and appropriate choice for integer values.
A) A reference to a location in memory.
B) A primitive value from its associated type.
C) A set of corresponding operations.
D) The category of the data type (primitive or reference).
Correct Answer: B
The content states, 'A variable of a primitive type holds a primitive value from that type.' This is a key distinction from reference types.
A) int price;
B) boolean price;
C) double price;
D) price double;
Correct Answer: C
A price with cents is a real number. The `double` data type is used for real numbers, and the syntax `double price;` is the correct way to declare it.
A) integer
B) boolean
C) variable
D) reference
Correct Answer: D
The provided text states, 'Data types can be categorized as either primitive or reference.'