Amazon Introduction To Coding 2 — Questions and Answers
Question 1: What is the primary purpose of a variable in programming?
- To store a value that can be referenced and changed later (Correct answer)
- To permanently lock data so it cannot change
- To display text on the screen automatically
- To connect a program to the internet
Correct answer: To store a value that can be referenced and changed later
A variable is a named container that holds a value which can be read or modified during execution.
Question 2: Which of the following is a Boolean value?
- true (Correct answer)
- 42
- "hello"
- 3.14
Correct answer: true
Boolean values are either true or false.
Question 3: What does a 'loop' allow a program to do?
- Repeat a block of code multiple times (Correct answer)
- Stop the program immediately
- Store a single number
- Change a variable's name
Correct answer: Repeat a block of code multiple times
Loops repeat instructions until a condition is met, avoiding duplicated code.
Question 4: In most languages, what symbol commonly ends a statement?
- Semicolon (;) (Correct answer)
- Question mark (?)
- At sign (@)
- Ampersand (&)
Correct answer: Semicolon (;)
Many languages like C, Java, and JavaScript use a semicolon to terminate statements.
Question 5: What is a function in programming?
- A reusable block of code that performs a task (Correct answer)
- A type of error message
- A fixed number that never changes
- A way to delete files
Correct answer: A reusable block of code that performs a task
Functions group instructions so they can be called repeatedly with different inputs.
Question 6: Which data structure stores an ordered collection of items accessed by index?
- Array (Correct answer)
- Boolean
- Character
- Pointer
Correct answer: Array
An array (or list) holds multiple values that are accessed by their numeric index.
Question 7: What is the term for finding and fixing errors in code?
- Debugging (Correct answer)
- Compiling
- Encrypting
- Caching
Correct answer: Debugging
Debugging is the process of locating and resolving bugs or defects in a program.
What is the primary purpose of a variable in programming?