D278 Exam Questions and Correct Answers
What is the purpose of a variable?
A variable stores data that can be used and modified during a program's execution.
How do you save a value to a variable?
By using the assignment operator (=), e.g., x = 5.
What is a programming expression?
A combination of variables, constants, operators, and functions that evaluates to a value.
What is an identifier?
A name used to identify variables, functions, arrays, or other user-defined elements.
What constitutes a valid identifier?
Must start with a letter or underscore, followed by letters, digits, or underscores, and cannot be a
keyword.
What is a literal?
A fixed value in code, such as 5 or "hello".
What is an operator?
A symbol that performs operations on variables and values (e.g., +, -, *, /).
What precedence rules does programming use?
Defines the order in which operators are evaluated; parentheses > multiplication/division >
addition/subtraction.
How does an integer differ from a float?
Integers are whole numbers; floats contain decimal points.
What happens if you divide two integers?
Integer division gives an integer (in some languages, it truncates).
, What happens if you divide an integer and a float?
Integer/float returns a float.
What happens if you divide a nonzero floating point number by zero?
Typically results in infinity or a runtime error, depending on the language.
How do you convert an item's type?
Through type casting, like int(), float(), or str().
What does the modulo operator do?
Returns the remainder of a division (e.g., 5 % 2 = 1).
What is the difference in a variable and a constant?
A variable's value can change; a constant's value cannot.
How does an array work?
Stores multiple values in indexed positions.
What does index reference?
The position of an element in an array, starting at 0.
What is the purpose of each different data type?
Defines how data is stored and what operations can be performed on it.
How does a branch differ from a loop?
A branch chooses between alternatives; a loop repeats actions.
How does an if-else branch work?
Evaluates a condition and runs one block of code if true, another if false.
What does the equality operator do?
Compares two values to see if they are equal; it generally works across most primitive types.
What are the four relational operators?
What is the purpose of a variable?
A variable stores data that can be used and modified during a program's execution.
How do you save a value to a variable?
By using the assignment operator (=), e.g., x = 5.
What is a programming expression?
A combination of variables, constants, operators, and functions that evaluates to a value.
What is an identifier?
A name used to identify variables, functions, arrays, or other user-defined elements.
What constitutes a valid identifier?
Must start with a letter or underscore, followed by letters, digits, or underscores, and cannot be a
keyword.
What is a literal?
A fixed value in code, such as 5 or "hello".
What is an operator?
A symbol that performs operations on variables and values (e.g., +, -, *, /).
What precedence rules does programming use?
Defines the order in which operators are evaluated; parentheses > multiplication/division >
addition/subtraction.
How does an integer differ from a float?
Integers are whole numbers; floats contain decimal points.
What happens if you divide two integers?
Integer division gives an integer (in some languages, it truncates).
, What happens if you divide an integer and a float?
Integer/float returns a float.
What happens if you divide a nonzero floating point number by zero?
Typically results in infinity or a runtime error, depending on the language.
How do you convert an item's type?
Through type casting, like int(), float(), or str().
What does the modulo operator do?
Returns the remainder of a division (e.g., 5 % 2 = 1).
What is the difference in a variable and a constant?
A variable's value can change; a constant's value cannot.
How does an array work?
Stores multiple values in indexed positions.
What does index reference?
The position of an element in an array, starting at 0.
What is the purpose of each different data type?
Defines how data is stored and what operations can be performed on it.
How does a branch differ from a loop?
A branch chooses between alternatives; a loop repeats actions.
How does an if-else branch work?
Evaluates a condition and runs one block of code if true, another if false.
What does the equality operator do?
Compares two values to see if they are equal; it generally works across most primitive types.
What are the four relational operators?