Fundamentals of Functional Programming Practice Questions

A-Levels · A-Level Computer Science · 150 free MCQs with instant results and detailed explanations.

150
Total
48
Easy
75
Medium
27
Hard

Start Practicing Fundamentals of Functional Programming

Take a timed quiz or customize your practice session

Quick Quiz (10 Qs) → Mock Test (25 Qs) ⚙ Customize

Sample Questions from Fundamentals of Functional Programming

Here are 10 sample questions. Start a quiz to get randomized questions with scoring.

Q1
Easy
Which of the following best describes a pure function in functional programming?
A. A function that always produces the same output for the same input.
B. A function that modifies global variables.
C. A function that can have side effects like printing to the console.
D. A function that does not return any value.
Show Answer & Explanation
Correct Answer: A
A pure function is defined by its consistency in output; it always returns the same result given the same inputs, and it does not have side effects that affect the program's state.
Q2
Easy
In functional programming, what is the purpose of a higher-order function?
A. It can only take numeric arguments.
B. It can return a function as a result.
C. It can only operate on lists.
D. It does not accept any parameters.
Show Answer & Explanation
Correct Answer: B
A higher-order function is defined as a function that can take one or more functions as arguments and/or return a function as its result, allowing for expressive and flexible code design.
Q3
Easy
What is the result of applying the following function: f(x) = x * 2 to the value 5?
A. 10
B. 7
C. 12
D. 15
Show Answer & Explanation
Correct Answer: A
The function f(x) = x * 2 doubles the input value. Thus, when applying it to 5, the result is 5 * 2 = 10.
Q4
Medium
Which of the following best describes a higher-order function in functional programming?
A. A function that manipulates variables.
B. A function that takes other functions as arguments or returns a function.
C. A function that performs input/output operations.
D. A function that is defined within another function.
Show Answer & Explanation
Correct Answer: B
A higher-order function is defined as a function that can take other functions as parameters or return them as results. This is a core concept in functional programming, enabling powerful abstractions and operations on functions.
Q5
Medium
Consider the following function definition in a functional programming language: `def square(x): return x * x`. What will `map(square, [1, 2, 3, 4])` return?
A. [1, 4, 9, 16]
B. [1, 2, 3, 4]
C. [2, 4, 6, 8]
D. [1, 3, 5, 7]
Show Answer & Explanation
Correct Answer: A
The `map` function applies the `square` function to each element of the list `[1, 2, 3, 4]`. Thus, the result is the list of squares: `[1*1, 2*2, 3*3, 4*4]`, which evaluates to `[1, 4, 9, 16]`.
Q6
Medium
In a functional programming paradigm, immutability is an essential characteristic. What does immutability imply?
A. Variables can be changed at any time.
B. Once a data structure is created, it cannot be modified.
C. Functions can have side effects.
D. Memory allocation is dynamic.
Show Answer & Explanation
Correct Answer: B
Immutability means that once a data structure is created, its state cannot be changed. This characteristic helps in avoiding side effects, making functions more predictable and easier to test.
Q7
Medium
Which of the following concepts in functional programming helps in avoiding side effects and maintaining state?
A. Iterative structures
B. Pure functions
C. Global variables
D. Mutable data types
Show Answer & Explanation
Correct Answer: B
Pure functions are functions that, given the same input, will always return the same output and have no side effects. This characteristic helps in maintaining predictable state and avoiding unintended interactions.
Q8
Hard
In a functional programming language, which of the following principles allows a function to be treated as a first-class citizen?
A. Immutability
B. Higher-order functions
C. Stateful computations
D. Procedural abstraction
Show Answer & Explanation
Correct Answer: B
Higher-order functions allow functions to be passed as arguments, returned from other functions, and assigned to variables, treating them as first-class citizens. This is a fundamental principle of functional programming.
Q9
Hard
Consider the following Haskell function: `map f xs = [f x | x <- xs]`. What will be the output of the expression `map (+1) [1, 2, 3, 4]`?
A. [1, 2, 3, 4]
B. [2, 3, 4, 5]
C. [1, 3, 5, 7]
D. [0, 1, 2, 3]
Show Answer & Explanation
Correct Answer: B
The `map` function applies the function `(+1)` to each element in the list `[1, 2, 3, 4]`, resulting in `[2, 3, 4, 5]` as each number is incremented by one.
Q10
Hard
Which of the following concepts in functional programming emphasizes the use of functions as first-class citizens?
A. Recursion
B. Higher-order functions
C. Immutable data
D. Side effects
Show Answer & Explanation
Correct Answer: B
Higher-order functions are those that can take other functions as arguments or return them as results. This characteristic underscores the importance of functions as first-class citizens in functional programming, allowing for flexible and modular code.

Showing 10 of 150 questions. Start a quiz to practice all questions with scoring and timer.

Practice All 150 Questions →

Fundamentals of Functional Programming โ€” A-Levels A-Level Computer Science Practice Questions Online

This page contains 150 practice MCQs for the chapter Fundamentals of Functional Programming in A-Levels A-Level Computer Science. The questions are organized by difficulty โ€” 48 easy, 75 medium, 27 hard โ€” so you can choose the right level for your preparation.

Every question includes a detailed explanation to help you understand the concept, not just memorize answers. Take a timed quiz to simulate exam conditions, or practice at your own pace with no time limit.