Programming Fundamentals – Flashcards & Quiz Questions
Introduces the basic building blocks of computer programs: data, control flow, functions, data structures and problem solving.
278 flashcards · 138 quiz questions · 7 topics
Get all 278 cards with Lifetime1. Programs, Algorithms and Problem Solving
Programs, Source Code and Translation · The Problem-Solving Process · Algorithms and Their Characteristics · Writing Algorithms in Pseudocode · Drawing Algorithms as Flowcharts
- What is a computer program?
- A program is a set of instructions that tells a computer what task to carry out. A programmer writes it in a programming language, and the computer follows the instructions step by step.
- What is source code?
- Source code is the human-readable text of a program written in a programming language. It is what the programmer writes before the program is translated into machine code.
- What is machine code?
- Machine code is the set of binary instructions that a computer's processor can execute directly. It is not meant to be read by humans, so programs written in a programming language must be translated into it.
Which description correctly defines source code?
- A. The human-readable text of a program written in a programming language
- B. The binary instructions that a processor executes directly
- C. The diagram that shows the decisions in a program
- D. The machine code produced after translation is complete
Source code is the readable text a programmer writes in a programming language. Binary processor instructions and translated machine code are the result of translation, and a diagram of decisions is a flowchart.
A student wants a program to run many times later without translating its text on every run. Which tool suits this need?
- A. An interpreter, which translates and runs each line every time
- B. A flowchart, which draws the program's steps as symbols
- C. Pseudocode, which writes the algorithm in plain structured language
- D. A compiler, which converts the whole source into machine code once before running
A compiler translates the entire source into machine code before running, leaving a program that can be executed repeatedly. An interpreter retranslates lines during each run, while flowcharts and pseudocode only describe an algorithm.
40 flashcards and 20 quiz questions in this topic.
2. Variables, Data Types and Operators
Variables and Declaration · Primitive Data Types · Assignment Operators and Expressions · Arithmetic Operators and Precedence · Boolean Values and Logical Operators
- What is a variable in programming?
- A variable is a named location in memory that stores a value which can change while the program runs.
- In the phrase 'named location in memory', what does the name actually refer to?
- The name is an identifier for a storage location; the value is the data held there. Changing the value leaves the name and the location unchanged.
- What must the first character of a variable name be?
- A variable name must begin with a letter or an underscore. It may not begin with a digit.
Which statement best describes a variable?
- A. A reserved keyword that signals the program should stop running
- B. A named location in memory that stores a value able to change while the program runs
- C. A fixed label in memory that stores one value that cannot ever change
- D. An instruction that tells the computer to add two numbers together
A variable is a named location in memory whose value can change while the program runs. The other options describe a constant, an arithmetic instruction and a control keyword, none of which is a variable.
Which of the following is a valid variable name in a typical programming language?
- A. student@Count
- B. student Count
- C. class
- D. studentCount
A valid name starts with a letter or underscore, then uses only letters, digits and underscores, and must not be a reserved keyword. studentCount follows all of these rules, while a space, a reserved word and an @ symbol each break one.
40 flashcards and 20 quiz questions in this topic.
3. Selection (Decision Structures)
Control Structures and Relational Conditions · The if Statement · The if-else Statement · Nested if and else-if Chains · Logical Operators and Switch Selection
- What is a control structure in programming?
- A control structure is a construct that controls the order in which a program's statements are executed. It decides whether, how many times, or in what order instructions run.
- What are the three basic control structures?
- The three basic control structures are sequence, selection and repetition, which is also called iteration.
- What happens in the sequence control structure?
- Statements are executed one after another in the order they appear, from top to bottom. Each statement runs exactly once, in straight-line fashion.
Which of the following lists the three basic control structures in programming?
- A. Assignment, comparison and iteration
- B. Sequence, selection and repetition
- C. Sequence, selection and storage
- D. Input, processing and output
The three basic control structures are sequence, selection and repetition, also known as iteration; the other lists mix in ideas like storage or input and output that are not control structures.
Which statement correctly describes what a relational operator does?
- A. It compares two values and gives a Boolean result of true or false
- B. It stores the result of a calculation in a variable
- C. It repeats a block of code while a condition holds
- D. It selects which block of code runs next
A relational operator compares two values and returns a Boolean result, either true or false, while storing values, repeating code and choosing blocks describe other constructs.
40 flashcards and 20 quiz questions in this topic.
4. Repetition (Loops)
Understanding Repetition and Loop Concepts · The While Loop and Condition Testing · The For Loop and Counted Repetition · Controlling Loops with Break and Continue · Infinite Loops and Common Pitfalls
- What is a loop in programming?
- A loop is a block of code that repeats while a condition holds or for a fixed number of times. Each repetition is called a pass or an iteration.
- Why is repetition useful in a program?
- Repetition lets one block of code handle many similar tasks, such as processing every item in a list or adding a series of numbers. It avoids writing the same statements over and over.
- What is condition-controlled repetition?
- It is repetition that continues only while a given condition stays true. The number of passes is not fixed in advance; it depends on when the condition stops holding.
Which statement best defines a loop in programming?
- A. A block of code that runs once and stores its result for later use by the program.
- B. A decision structure that selects one path and skips all the other available paths.
- C. A container that holds a list of values so they can be processed later.
- D. A block of code that repeats while a condition holds or for a fixed number of times.
A loop is defined by repeating a block of code while a condition holds or for a fixed number of times. The other choices describe a one-off statement, a decision, and a data container, none of which repeat code.
When is a for loop normally the appropriate choice?
- A. When the loop must keep running until valid input is entered.
- B. When the stopping condition changes with each pass of the loop.
- C. When the body must run zero or more times depending on data.
- D. When the number of repetitions is known before the loop begins.
A for loop is normally used for counted repetition, where the number of passes is fixed in advance. The other choices describe situations where the number of passes depends on a changing condition, which calls for condition-controlled repetition.
39 flashcards and 19 quiz questions in this topic.
5. Functions
Introduction to Functions and Calls · Parameters and Arguments · Returning Values from Functions · Local and Global Variable Scope · Recursion and Base Cases
- What is a function in programming?
- A function is a named block of code that performs one task. It can be called many times from different places in a program.
- What does it mean to call a function?
- Calling a function means writing its name followed by parentheses so the program runs the code inside it. The body runs each time the call is made.
- How does defining a function help you avoid duplicated code?
- You write the instructions once inside the function, then call the function wherever those instructions are needed. This replaces copying the same lines into several places.
Which statement accurately describes a function in programming?
- A. A named block of code that does one task and can be called many times.
- B. A loop that repeats the same statement until a condition changes.
- C. A stored value that cannot be changed while the program runs.
- D. A comment that explains what a later block of code does.
A function is identified by a name, carries out a single task, and may be called repeatedly. A loop repeats statements, a fixed value is a constant, and a comment only explains code without running it.
A student copies the same five lines that compute a grade into three different places in a program. What is the main problem with this approach?
- A. The lines are repeated, so any change must be made in three places.
- B. The program will run more slowly because the lines appear three times.
- C. The five lines will produce different results each time they are written.
- D. The computer cannot store five lines in more than one place.
Repeating the same lines means a correction has to be applied in every copy, which is easy to get wrong. Placing those lines in one function lets every call use the single corrected version.
40 flashcards and 19 quiz questions in this topic.
6. Arrays, Lists and Strings
Arrays and Lists Fundamentals · Working with Array Elements · Strings as Character Sequences · Two-Dimensional Arrays and Tables · Searching Arrays and Lists
- What is an array or list?
- An array or list is a data structure that stores many values under a single name. Each individual value is reached by an index.
- What is an index in an array or list?
- An index is a number that identifies the position of an element in an array or list. It is used to reach that specific element.
- What does it mean when indexing starts at zero?
- It means the first element is stored at index 0, so positions are counted from zero rather than from one.
Which statement describes an array or list?
- A. It stores a single value and renames it each time that value changes.
- B. It stores many values under one name and reaches each by an index.
- C. It stores one value under many names and reaches it by its content.
- D. It stores many values under different names in the order they were added.
An array or list groups many values under a single name, and each value is accessed using its index. The other statements contradict this by describing single values or many different names.
A list contains five values and uses zero-based indexing. Which index refers to the first value?
- A. The first value is found at index five.
- B. The first value has no index at all.
- C. The first value is found at index zero.
- D. The first value is found at index one.
With zero-based indexing, counting begins at zero, so the first element is located at index zero. Indexes one and five refer to later positions or beyond the list.
40 flashcards and 20 quiz questions in this topic.
7. Testing and Debugging
Types of Program Errors · Reading and Interpreting Error Messages · Designing Test Cases and Data · Debugging Process, Tools and Techniques · Comments and Defensive Coding Habits
- What is a syntax error, and when does it stop a program?
- A syntax error breaks the rules of the programming language. It stops the program from being compiled or run, so nothing executes until the mistake is fixed.
- What is a runtime error, and give a typical example.
- A runtime error occurs while the program is running. A typical example is dividing by zero.
- What is a logic error?
- A logic error lets the program run but produces a wrong result. The code follows the language rules, yet the outcome is incorrect.
Which type of error breaks the rules of the language and prevents the program from being compiled or run?
- A. A runtime error
- B. A logic error
- C. A debugging error
- D. A syntax error
A syntax error breaks the language's rules, so compilation fails and the program never runs.
A program compiles successfully, but when the user enters zero as a divisor it stops with a failure message. Which error is this?
- A. A logic error, because the result is wrong
- B. A runtime error, because it happens while the program is running
- C. A syntax error, because the code will not compile
- D. A comment error, because notes affect execution
The failure happens during execution when dividing by zero, which is a runtime error; the code had already compiled.
39 flashcards and 20 quiz questions in this topic.
Study every card
Every card and question in this course comes with the Lifetime package. Add it to GoodScores and practise with flashcards, quizzes and spaced review.
Get all 278 cards with Lifetime