QCM : Programming Language Paradigms — 18 questions

Questions et réponses du QCM

1. Which statement best defines a programming paradigm in terms of code structure?

A programming language is the executable tool used to write code.
A programming paradigm is a fundamental style or mindset that structures code using specific rules, abstractions, and computational models.
A programming paradigm is the data that programs store while running.
A programming paradigm is the concrete syntax of a single programming language.

A programming paradigm is a fundamental style or mindset that structures code using specific rules, abstractions, and computational models.

Explication

A programming paradigm is the fundamental style or philosophy that guides how code is structured, not the language’s name or syntax. The distractors confuse paradigms with languages or with runtime state.

2. What distinguishes a programming language from a programming paradigm?

A programming language and a paradigm are the same concept with different labels.
A programming language is a tool (such as Python or C++), while a programming paradigm is the philosophy guiding how that tool structures computation.
A programming language is the philosophy behind computation, while a paradigm is the tool used to code.
A programming language determines program state changes, while a paradigm determines only memory size.

A programming language is a tool (such as Python or C++), while a programming paradigm is the philosophy guiding how that tool structures computation.

Explication

The paradigm is the guiding philosophy for structuring computation, whereas the language is the tool used to implement it. The distractors swap the definitions or introduce incorrect aspects like memory size.

3. In a running program, what does the term state refer to?

The programming language’s runtime libraries only.
The data stored in memory at a given moment during execution.
The program’s fixed control-flow structure in the compiler.
The source code text before compilation.

The data stored in memory at a given moment during execution.

Explication

State is the data stored in memory at a particular moment during execution. The distractors redefine state as source code, control-flow structure, or libraries.

4. What best describes state mutation during program execution?

Writing a new source file and recompiling it.
Changing memory values in place over time during execution.
Creating a new program thread without changing any stored values.
Swapping the meaning of variables in the compiler’s symbol table.

Changing memory values in place over time during execution.

Explication

State mutation is the act of changing memory values in place over time. The distractors describe actions that may involve execution but do not directly define in-place state changes.

5. How are the two primary programming paradigm branches imperative and declarative classified?

By whether the program uses a graphical user interface.
By how they handle state and control flow.
By whether the program uses static typing or dynamic typing.
By whether the code is written in a high-level or low-level language.

By how they handle state and control flow.

Explication

Imperative and declarative are distinguished based on their treatment of state and control flow. The distractors categorize by unrelated properties like UI or typing.

6. Which description best matches the imperative paradigm?

It defines computation purely through mathematical proofs without execution steps.
It specifies what result is required without describing steps.
It computes a solution step by step by explicitly manipulating program state.
It only describes data structures while forbidding any control flow.

It computes a solution step by step by explicitly manipulating program state.

Explication

Imperative programming specifies computation step by step with explicit state manipulation. The distractor describes declarative programming rather than imperative.

7. Which choice best fits the declarative paradigm?

It requires for/while loops as the main control mechanism.
It always relies on mutable variables to guide computation.
It specifies what result is required without detailing how it is executed step by step.
It details step-by-step execution instructions.

It specifies what result is required without detailing how it is executed step by step.

Explication

Declarative programming focuses on specifying the required result, leaving execution details to the underlying system. The distractors either describe imperative execution or introduce incorrect requirements.

8. What is the common state-related difference between imperative and declarative programs?

Imperative programs use immutable state, while declarative programs use mutable state.
Both imperative and declarative programs use the same immutable state model.
Imperative programs generally use mutable state, whereas declarative programs use immutable state that cannot be modified in place.
Declarative programs modify state in place, while imperative programs avoid state entirely.

Imperative programs generally use mutable state, whereas declarative programs use immutable state that cannot be modified in place.

Explication

Imperative programs typically rely on mutable state, while declarative programs use immutable state that cannot be changed in place. The distractors invert or add incorrect claims about state behavior.

9. Which control-flow mechanisms are commonly associated with the declarative paradigm (as compared to imperative)?

Assignment-based control flow with mutable counters as the main tool
Direct jump tables with imperative branching only
for/while loops, explicit if branching, and jumps
Recursion, higher-order functions, and pattern matching

Recursion, higher-order functions, and pattern matching

Explication

Declarative control flow is commonly associated with recursion, higher-order functions, and pattern matching. The distractor lists mechanisms described as imperative control flow.

10. How do side effects typically differ between imperative and declarative programming?

Side effects are common and expected in imperative programming, while declarative programming minimizes or eliminates them.
Both paradigms treat side effects as equally central and unavoidable.
Imperative programming minimizes side effects, while declarative programming uses many side effects.
Imperative programming eliminates side effects, while declarative programming expects side effects.

Side effects are common and expected in imperative programming, while declarative programming minimizes or eliminates them.

Explication

Imperative programming commonly expects side effects, whereas declarative programming minimizes or completely eliminates them. The distractors reverse or equalize the side-effect expectations.

11. In the imperative approach over the array [1, 2, 3, 4, 5], what happens to the running total when an even element is encountered?

It is ignored and the total remains unchanged
It causes the loop to terminate early
It is added to the total in place
It triggers an update to reset the total

It is ignored and the total remains unchanged

Explication

The imperative solution filters out even numbers, so the total only increases when an element is odd. Therefore an even element leaves the total unchanged.

12. In the declarative approach for [1, 2, 3, 4, 5], which expression captures the computation?

sum (filter odd numbers)
odd numbers are added using a mutable accumulator
filter odd numbers (then add element by element)
sum (filter even numbers)

sum (filter odd numbers)

Explication

The declarative solution computes the result as the sum of the odd elements using a filtering transformation. The other options describe filtering evens or using imperative-style iteration.

13. How can matching a programming paradigm to a system domain reduce bug density?

It replaces the need for testing by making programs self-correcting
It forces a single paradigm to be used everywhere in the system
It guarantees fewer bugs regardless of implementation quality
It aligns the paradigm with system requirements and lowers defects

It aligns the paradigm with system requirements and lowers defects

Explication

The rule states that aligning a paradigm with the system's requirements can reduce bug density. The other options contradict the idea by overclaiming guarantees or exclusivity.

14. Why can functional immutability help in multithreaded systems?

It solves race conditions only when functions are non-deterministic
It increases race conditions by removing all synchronization
It prevents race conditions by avoiding in-place state changes
It requires using only imperative loops to share data

It prevents race conditions by avoiding in-place state changes

Explication

Immutability avoids in-place state changes, which helps prevent race conditions in multithreaded contexts. The distractors either invert the effect or add unsupported conditions.

15. Which combination best matches the architectural approach described for modern enterprise systems?

Declarative markup for domain logic, object-oriented ETL, and functional UI rendering
Object-oriented markup for ETL, functional pipelines for domain models, and imperative YAML setup
Object-oriented domain entities, functional pipelines for ETL, and declarative markup for UI/config
Functional domain entities, imperative ETL loops, and object-based UI code only

Object-oriented domain entities, functional pipelines for ETL, and declarative markup for UI/config

Explication

The example explicitly combines object-oriented models for domain entities, functional pipelines for ETL, and declarative markup like HTML or YAML for UI and configuration. The other choices mix paradigms in ways not described.

16. A function can be replaced by its resulting value without changing program behavior; under what condition is it referentially transparent?

When substitution with the result does not change behavior
When it performs logging in addition to returning a value
When it always returns the same value for the same inputs
When it produces output that depends only on its arguments

When substitution with the result does not change behavior

Explication

Referential transparency means the function can be replaced by its result without changing program behavior. Deterministic returns alone are insufficient if behavior changes via side effects.

17. Why is add(x, y) = x + y referentially transparent?

It performs output to the console but still counts as referentially transparent
It returns the same result for the same inputs and has no side effects
It reads mutable global state to determine the sum
It may return different values for the same inputs if execution order changes

It returns the same result for the same inputs and has no side effects

Explication

The description ties referential transparency to consistent results and the absence of side effects. Printing or global-state reading would violate that property.

18. Why is add_with_log(x, y) not referentially transparent?

It returns x + y, which is deterministic
It prints to the console, which is an I/O side effect
It takes two inputs and computes a pure arithmetic result
It always outputs the same text for the same inputs

It prints to the console, which is an I/O side effect

Explication

add_with_log is not referentially transparent because console output is an I/O side effect that changes observable behavior. Deterministic arithmetic alone is not enough.

Révisez avec les flashcards

Mémorisez les réponses avec 30 flashcards sur Programming Language Paradigms.

What is a programming paradigm?

A fundamental style or approach for structuring computer code.

What distinguishes a programming language from a programming paradigm?

A language is a tool, while a paradigm is the guiding philosophy.

What is true about most modern programming languages regarding paradigms?

They support multiple paradigms like object-oriented, functional, and procedural.

Voir les flashcards →

Approfondir avec la fiche

Consultez la fiche de révision complète sur Programming Language Paradigms.

Voir la fiche →

Cours similaires

Crée tes propres QCM

Importe ton cours et l'IA génère des QCM avec corrections en 30 secondes.

Générateur de QCM