Q.1 What is the primary focus of functional programming?
Data Encapsulation
State Management
Function Evaluation
Class Inheritance
Explanation - Functional programming emphasizes computation through mathematical functions and avoids changing states or mutable data.
Correct answer is: Function Evaluation
Q.2 Which of the following is a key feature of functional programming?
Mutable state
First-class functions
Global variables
Inheritance
Explanation - In functional programming, functions are treated as first-class citizens, meaning they can be passed as arguments, returned, and assigned to variables.
Correct answer is: First-class functions
Q.3 In functional programming, 'pure functions' are defined as functions that:
Always return random results
Do not depend on external state and always return the same output for the same input
Modify global variables
Run only once
Explanation - Pure functions avoid side effects and guarantee predictable results, which makes reasoning about programs easier.
Correct answer is: Do not depend on external state and always return the same output for the same input
Q.4 Which language is most commonly associated with functional programming?
Java
C
Haskell
C++
Explanation - Haskell is a purely functional programming language designed with functional principles at its core.
Correct answer is: Haskell
Q.5 What does immutability mean in functional programming?
Data cannot be changed after creation
Data can be modified only by administrators
Variables are private
Data is stored in cache memory
Explanation - Immutability ensures data consistency and avoids side effects in functional programming.
Correct answer is: Data cannot be changed after creation
Q.6 Which concept allows passing a function as an argument to another function?
Encapsulation
Higher-order functions
Recursion
Composition
Explanation - Higher-order functions take other functions as parameters or return them as results, enabling flexible program design.
Correct answer is: Higher-order functions
Q.7 What is recursion in functional programming?
A function calling itself
A function repeating infinitely
A variable storing multiple values
A memory optimization technique
Explanation - Recursion is a core technique in functional programming, used as an alternative to traditional loops.
Correct answer is: A function calling itself
Q.8 Which of the following is NOT typically associated with functional programming?
Side effects
Immutability
Recursion
Function composition
Explanation - Functional programming tries to minimize or eliminate side effects for predictability and reliability.
Correct answer is: Side effects
Q.9 Function composition in functional programming means:
Combining two or more functions to produce a new function
Writing functions inside loops
Overloading operators with functions
Encapsulating functions in classes
Explanation - Composition allows building complex behavior by chaining simple functions together.
Correct answer is: Combining two or more functions to produce a new function
Q.10 What is a 'lambda expression' in functional programming?
A recursive function
An anonymous function
A data structure
A type of loop
Explanation - Lambda expressions allow defining small, unnamed functions for short-term use.
Correct answer is: An anonymous function
Q.11 Which of the following best describes 'referential transparency'?
An expression can be replaced with its value without changing the program's behavior
Functions cannot call themselves
Data is always mutable
Every function must return a string
Explanation - Referential transparency ensures predictability by eliminating hidden dependencies or side effects.
Correct answer is: An expression can be replaced with its value without changing the program's behavior
Q.12 In functional programming, lazy evaluation means:
Evaluating expressions only when needed
Avoiding function calls
Skipping computations permanently
Running programs slower
Explanation - Lazy evaluation delays computation until its result is actually required, improving efficiency.
Correct answer is: Evaluating expressions only when needed
Q.13 Which of the following is an advantage of pure functions?
They are faster than all functions
They reduce complexity and make debugging easier
They use less memory
They guarantee parallelism
Explanation - Pure functions are predictable, making programs easier to test and maintain.
Correct answer is: They reduce complexity and make debugging easier
Q.14 Map, filter, and reduce are examples of:
Control structures
Higher-order functions
Data types
Class methods
Explanation - These are standard higher-order functions used to process collections in functional programming.
Correct answer is: Higher-order functions
Q.15 Currying in functional programming refers to:
Transforming a function with multiple arguments into a sequence of functions each with one argument
Storing multiple results of a function
Naming a function dynamically
Inlining a recursive call
Explanation - Currying breaks down functions into simpler forms for easier composition and reuse.
Correct answer is: Transforming a function with multiple arguments into a sequence of functions each with one argument
Q.16 Which of the following languages is purely functional?
Python
Scala
Haskell
JavaScript
Explanation - While many languages support functional features, Haskell is purely functional by design.
Correct answer is: Haskell
Q.17 What is a monad in functional programming?
A design pattern for handling side effects
A type of loop
A global variable
A syntax for recursion
Explanation - Monads provide a structure for managing side effects while maintaining functional purity.
Correct answer is: A design pattern for handling side effects
Q.18 Which of the following is an example of a pure function?
A function that reads a file and returns its content
A function that adds two numbers
A function that updates a global counter
A function that prints to the screen
Explanation - Pure functions return results based only on their input without side effects.
Correct answer is: A function that adds two numbers
Q.19 In functional programming, side effects refer to:
A function returning a value
A function modifying external state or I/O
A program running slowly
An unexpected error
Explanation - Side effects occur when a function changes state outside its scope, which is discouraged in functional programming.
Correct answer is: A function modifying external state or I/O
Q.20 Which of the following best describes immutability?
Variables can be reassigned freely
Data structures cannot be changed once created
Programs run faster with more memory
Functions can be redefined
Explanation - Immutability ensures data consistency and predictability in functional programming.
Correct answer is: Data structures cannot be changed once created
Q.21 What role does recursion play in functional programming?
It replaces loops for iteration
It makes programs slower
It increases memory usage
It is used only for sorting
Explanation - Recursion is a common way to express iteration in functional programming since loops are less common.
Correct answer is: It replaces loops for iteration
Q.22 Which of the following is an example of higher-order function usage?
map(function, list)
int x = 5;
x + y
while loop
Explanation - The map function applies another function to each item in a collection, making it a higher-order function.
Correct answer is: map(function, list)
Q.23 Lazy evaluation is useful because:
It avoids unnecessary computations
It forces early errors
It disables recursion
It optimizes memory always
Explanation - Lazy evaluation delays execution until necessary, improving efficiency for large or infinite structures.
Correct answer is: It avoids unnecessary computations
Q.24 Which of the following is NOT a functional programming concept?
Immutability
Inheritance
Pure functions
Function composition
Explanation - Inheritance is associated with object-oriented programming, not functional programming.
Correct answer is: Inheritance
Q.25 Which of the following best represents a functional paradigm?
Using objects to represent real-world entities
Using functions without side effects to model computations
Using pointers to manipulate memory
Using classes to encapsulate state
Explanation - Functional programming is based on pure functions and avoiding mutable state.
Correct answer is: Using functions without side effects to model computations
