B.S.W.E. Bachelor of Software Engineering Programming Languages & Paradigms 1 — Questions and Answers
Question 1: Which of the following best describes a strongly typed programming language?
- A language that requires explicit type declarations for all variables
- A language that enforces type constraints and restricts implicit type conversions (Correct answer)
- A language that compiles exclusively to native machine code
- A language that uses only integer and floating-point types
Correct answer: A language that enforces type constraints and restricts implicit type conversions
A strongly typed language enforces type constraints at compile or runtime and does not allow implicit coercions between incompatible types.
Question 2: Which programming paradigm treats computation as the evaluation of mathematical functions and emphasizes immutability?
- Object-oriented programming
- Event-driven programming
- Procedural programming
- Functional programming (Correct answer)
Correct answer: Functional programming
Functional programming models computation as the evaluation of pure mathematical functions, emphasizing immutability and the avoidance of side effects.
Question 3: What is the primary role of a compiler in the software development process?
- To interpret source code line by line at runtime
- To manage memory allocation during program execution
- To translate source code into machine code before execution (Correct answer)
- To debug programs by stepping through instructions
Correct answer: To translate source code into machine code before execution
A compiler translates the entire source program into machine code (or intermediate code) before execution, unlike an interpreter which processes code at runtime.
Question 4: Which of the following is the best example of a declarative programming language?
- C
- Java
- Python
- SQL (Correct answer)
Correct answer: SQL
SQL is declarative because the programmer specifies what data to retrieve without defining the step-by-step procedure for how to retrieve it.
Question 5: What does dynamic typing mean in the context of programming languages?
- Variable types are resolved at compile time
- Types are checked at runtime rather than at compile time (Correct answer)
- Types change automatically based on available memory
- The compiler infers all types from surrounding context
Correct answer: Types are checked at runtime rather than at compile time
In dynamically typed languages, type checking is performed at runtime, allowing variables to hold values of any type without explicit prior declarations.
Question 6: What does 'garbage collection' refer to in programming language runtimes?
- Removing dead code from source files during compilation
- Clearing temporary files created by the build system
- Automatic reclamation of heap memory no longer referenced by the program (Correct answer)
- Flushing CPU cache between context switches
Correct answer: Automatic reclamation of heap memory no longer referenced by the program
Garbage collection is an automatic memory management technique that identifies and frees heap memory that is no longer reachable by any live references in the program.
Question 7: Which of the following best describes the concept of a 'closure' in programming?
- A class that cannot be extended or instantiated
- A function that captures and retains variables from its enclosing lexical scope (Correct answer)
- A data structure that encapsulates a collection of related operations
- A method that releases file handles after use
Correct answer: A function that captures and retains variables from its enclosing lexical scope
A closure is a function bundled together with references to its surrounding lexical environment, retaining access to those variables even after the enclosing scope has returned.
Which of the following best describes a strongly typed programming language?