A2 Chapter 13. Data Representation Flashcards
What is a variable in programming?
- A named location in memory used to store data.
- The value of a variable can change during program execution.
What is a constant in programming?
- A named location in memory with a value that cannot be changed during program execution.
- Used to store fixed values.
What are data types in programming?
- Categories of data that define the operations that can be performed on the data and the way the data is stored.
- Examples: Integer, Float, String, Boolean.
What is an array in programming?
- A collection of elements of the same data type, stored in contiguous memory locations.
- Accessed using an index.
What is a function in programming?
- A block of code designed to perform a specific task.
- Can be reused multiple times in a program.
What is the difference between a procedure and a function?
- Procedure: A block of code that performs a task but does not return a value.
- Function: A block of code that performs a task and returns a value.
What is recursion in programming?
- A technique where a function calls itself to solve smaller instances of the same problem.
- Used in problems like factorial calculation, Fibonacci sequence.
What are control structures in programming?
- Constructs that control the flow of execution in a program.
- Types: Sequence, Selection (if-else), Iteration (loops).
What is a loop in programming?
- A control structure that repeats a block of code as long as a specified condition is true.
- Examples: For loop, While loop.
What is the purpose of an if-else statement?
- A control structure used to execute different blocks of code based on a condition.
- Allows decision-making in a program.
What is a switch/case statement?
- A control structure that allows a variable to be tested for equality against a list of values.
- Executes the block of code corresponding to the matching case.
What is the difference between a for loop and a while loop?
- For loop: Executes a block of code a specific number of times.
- While loop: Executes a block of code as long as a condition is true.
What is a nested loop?
- A loop inside another loop.
- The inner loop is executed completely for each iteration of the outer loop.
What is an exception in programming?
- An error that occurs during the execution of a program.
- Can be handled using try-catch blocks to prevent program crashes.
What is the purpose of debugging?
- The process of finding and fixing errors or bugs in a program.
- Ensures the program runs correctly and efficiently.
What is object-oriented programming (OOP)?
- A programming paradigm based on the concept of objects.
- Objects are instances of classes, which can contain data (attributes) and methods (functions).
What are the four main principles of OOP?
- Encapsulation: Hiding the internal state of an object and requiring all interaction to be performed through an object’s methods.
- Abstraction: Hiding complex implementation details and showing only the necessary features.
- Inheritance: A mechanism for creating a new class using the properties and methods of an existing class.
- Polymorphism: The ability to present the same interface for different underlying forms (data types).
What is a class in OOP?
- A blueprint for creating objects.
- Defines the attributes and methods that the objects created from the class will have.
What is an object in OOP?
- An instance of a class.
- Contains data (attributes) and methods (functions) to manipulate that data.
What is the difference between compile-time and run-time errors?
- Compile-time errors: Errors detected by the compiler during the translation of source code to machine code.
- Run-time errors: Errors that occur during the execution of a program.
What is a constructor in OOP?
- A special method used to initialize objects of a class.
- Called automatically when an object is created.
What is inheritance in OOP?
- A mechanism that allows one class to inherit properties and methods from another class.
- Promotes code reuse and hierarchical class relationships.
What is method overloading?
- A feature in OOP where multiple methods in the same class have the same name but different parameters.
- Allows different ways to call a method depending on the input.
What is method overriding?
- A feature in OOP where a subclass provides a specific implementation of a method already defined in its superclass.
- Allows a subclass to provide a specific behavior for a method.