ads

Functional Programming MCQ

 Functional Programming MCQ - part 1

Multiple-choice questions (MCQs) based on an introduction to functional programming along with their answers:





1. What is functional programming?

   a) A programming paradigm based on imperative instructions

   b) A programming paradigm based on mathematical functions

   c) A programming paradigm based on object-oriented principles

   d) A programming paradigm based on procedural approach

   Answer: b


2. Which of the following is a key characteristic of functional programming?

   a) Mutation of variables

   b) Emphasis on loops and iterations

   c) Avoidance of side effects

   d) Reliance on global state

   Answer: c


3. In functional programming, functions are treated as:

   a) Procedures

   b) Objects

   c) First-class citizens

   d) Variables

   Answer: c


4. What does immutability refer to in functional programming?

   a) The ability to change data once it's created

   b) The inability to create new data

   c) The inability to change existing data

   d) The ability to mutate data at runtime

   Answer: c


5. Which of the following languages is NOT commonly associated with functional programming?

   a) Python

   b) Haskell

   c) Lisp

   d) Scala

   Answer: a


6. What is a pure function?

   a) A function that doesn't return any value

   b) A function with side effects

   c) A function that always produces the same output for a given input

   d) A function that relies on global variables

   Answer: c


7. Which of the following is a benefit of using pure functions?

   a) They can have side effects

   b) They are difficult to reason about

   c) They are easier to test and debug

   d) They rely heavily on mutable data

   Answer: c


8. What is recursion in functional programming?

   a) A looping construct

   b) A function that calls itself

   c) A conditional statement

   d) A method for handling exceptions

   Answer: b


9. Which of the following is a higher-order function?

   a) A function that operates on functions

   b) A function with no return value

   c) A function that modifies global state

   d) A function that performs arithmetic operations

   Answer: a


10. What is currying in functional programming?

    a) A process of converting a function with multiple arguments into a sequence of functions, each taking a single argument

    b) A process of concatenating strings

    c) A process of converting a function into a pure function

    d) A process of converting a function into a recursive function

    Answer: a


11. Which of the following is NOT a higher-order function?

    a) map

    b) filter

    c) reduce

    d) sort

    Answer: d


12. What does the map function do in functional programming?

    a) Filters elements based on a predicate

    b) Reduces a collection to a single value

    c) Applies a function to each element in a collection

    d) Sorts a collection in ascending order

    Answer: c


13. Which of the following is an example of a side effect?

    a) Printing a value to the console

    b) Returning the result of a computation

    c) Adding two numbers together

    d) Assigning a new value to a variable

    Answer: a


14. Which of the following is NOT a characteristic of functional programming languages?

    a) Strong typing

    b) Dynamic typing

    c) Static typing

    d) Type inference

    Answer: b


15. What is tail recursion?

    a) A recursive function that doesn't call itself

    b) A recursive function where the recursive call is the last operation performed by the function

    c) A recursive function that calls another function

    d) A recursive function with multiple base cases

    Answer: b


16. Which of the following languages supports pattern matching?

    a) JavaScript

    b) Ruby

    c) Scala

    d) PHP

    Answer: c


17. What is lazy evaluation in functional programming?

    a) Delaying the evaluation of an expression until its value is needed

    b) Eagerly evaluating all expressions

    c) Evaluating expressions in parallel

    d) Ignoring evaluation of expressions

    Answer: a


18. Which of the following is NOT a benefit of functional programming?

    a) Concise and expressive code

    b) Improved parallelism and concurrency

    c) Reduced likelihood of bugs

    d) Heavy reliance on mutable state

    Answer: d


19. What is a closure in functional programming?

    a) A function that has access to its own local variables

    b) A function that has access to variables in its lexical scope

    c) A function that returns another function

    d) A function that modifies global state

    Answer: b


20. What is referential transparency?

    a) The property that allows replacing a function call with its result without changing the program's behavior

    b) The property of a function that always produces the same output for the same input

    c) The property of a function that modifies its arguments

    d) The property of a function that performs I/O operations

    Answer: a


21. What does the term "side effect" refer to in functional programming?

    a) The primary output of a function

    b) The secondary output of a function

    c) Any change to the program state that is observable outside the called function

    d) The result of a function call

    Answer: c


22. Which of the following is an advantage of immutability in functional programming?

    a) It allows for more efficient memory usage

    b) It simplifies reasoning about code

    c) It enables functions to have side effects

    d) It makes debugging more challenging

    Answer: b


23. Which of the following is NOT a fundamental concept in functional programming?

    a) Abstraction

    b) Encapsulation

    c) Composition

    d) Recursion

    Answer: b


24. Which of the following statements is true about higher-order functions?

    a) Higher-order functions cannot accept functions as arguments

    b) Higher-order functions can only return functions as results

    c) Higher-order functions can accept functions as arguments and/or return functions as results

    d) Higher-order functions can only accept primitive data types as arguments

    Answer: c


25. What is pattern matching in functional programming?

    a) A technique for finding patterns in strings

    b) A way to match function signatures

    c) A method for decomposing data structures based on their shape

    d) A process of comparing two lists for equality

    Answer: c


26. What is the primary focus of functional programming?

    a) Managing state changes

    b) Iterative algorithms

    c) Declarative programming

    d) Object instantiation

    Answer: c


27. Which of the following is a common data structure used in functional programming?

    a) Arrays

    b) Linked lists

    c) Stacks

    d) All of


 the above

    Answer: d


28. What is the advantage of using recursion in functional programming?

    a) Recursion is easier to understand than loops

    b) Recursion allows for more efficient memory usage

    c) Recursion is more suitable for parallel processing

    d) Recursion can express certain algorithms more naturally

    Answer: d


29. Which of the following is NOT a pure function?

    a) Addition of two numbers

    b) Generating a random number

    c) Finding the length of a list

    d) Sorting a list of integers

    Answer: b


30. What does it mean for a function to be idempotent?

    a) The function produces the same output for every input

    b) The function has no side-effects

    c) The function can be applied multiple times without changing the result

    d) The function modifies its input arguments

    Answer: c


31. Which of the following is a disadvantage of using immutability in functional programming?

    a) It leads to more concise code

    b) It makes it harder to model state changes

    c) It simplifies concurrent programming

    d) It reduces the need for defensive programming

    Answer: b


32. What is the purpose of the fold function in functional programming?

    a) To concatenate strings

    b) To apply a function to each element of a collection

    c) To reduce a collection to a single value

    d) To sort a collection

    Answer: c


33. What is a monad in functional programming?

    a) A type of higher-order function

    b) A design pattern for managing side effects

    c) A mathematical concept used to represent computations as sequences of steps

    d) A data structure for storing key-value pairs

    Answer: c


34. Which of the following is NOT a common characteristic of functional programming languages?

    a) Imperative style

    b) First-class functions

    c) Lambda calculus

    d) Type inference

    Answer: a


35. Which of the following is NOT a principle of functional programming?

    a) Avoiding mutable state

    b) Emphasizing declarative code

    c) Encouraging side effects

    d) Using higher-order functions

    Answer: c


36. What is point-free style in functional programming?

    a) A style of programming where functions do not mention their arguments

    b) A style of programming where functions are called with explicit arguments

    c) A style of programming where functions rely heavily on side effects

    d) A style of programming where functions are defined using loops

    Answer: a


37. What is the main goal of lazy evaluation in functional programming?

    a) To delay the execution of functions until they are needed

    b) To execute functions eagerly

    c) To execute functions in parallel

    d) To avoid using functions altogether

    Answer: a


38. Which of the following is a benefit of using immutability in functional programming?

    a) It allows for more flexible code

    b) It makes reasoning about code easier

    c) It increases the likelihood of side effects

    d) It reduces the need for recursion

    Answer: b


39. Which of the following is NOT a higher-order function commonly used in functional programming?

    a) zip

    b) flatMap

    c) takeWhile

    d) forEach

    Answer: d


40. What is the difference between map and flatMap functions in functional programming?

    a) map applies a function to each element of a collection while flatMap applies a function and then flattens the result

    b) map applies a function and then flattens the result while flatMap applies a function to each element of a collection

    c) map is used for iteration while flatMap is used for mapping elements to keys

    d) There is no difference between map and flatMap functions

    Answer: a


41. Which of the following is an advantage of using pure functions in functional programming?

    a) They rely heavily on mutable state

    b) They can have side effects

    c) They are easier to test and reason about

    d) They always produce different outputs for the same inputs

    Answer: c


42. What is the role of tail call optimization in functional programming languages?

    a) It ensures that recursive functions terminate correctly

    b) It reduces the memory usage of recursive functions

    c) It optimizes the performance of recursive functions

    d) It prevents stack overflow errors in recursive functions

    Answer: d


43. Which of the following is NOT a common use case for functional programming?

    a) Web development

    b) Data processing

    c) Artificial intelligence

    d) Real-time systems programming

    Answer: d


44. What does the term "referential transparency" mean in functional programming?

    a) The ability to refer to values directly without storing them

    b) The property that allows replacing an expression with its value without changing the program's behavior

    c) The ability to reference external variables in a function

    d) The property of a function that always produces the same output for the same input

    Answer: b


45. Which of the following is NOT a common operation performed on collections in functional programming?

    a) Filtering

    b) Sorting

    c) Concatenating

    d) Iterating

    Answer: d


46. What is the purpose of higher-order functions in functional programming?

    a) To make functions easier to understand

    b) To allow functions to be treated as data

    c) To reduce the need for recursion

    d) To enforce strict typing

    Answer: b


47. What is the advantage of using pattern matching in functional programming?

    a) It simplifies conditional logic

    b) It increases the complexity of code

    c) It makes code less readable

    d) It only works with primitive data types

    Answer: a


48. Which of the following is NOT a benefit of immutability in functional programming?

    a) It simplifies concurrent programming

    b) It reduces the likelihood of bugs

    c) It allows for mutable state

    d) It simplifies reasoning about code

    Answer: c


49. What is the primary focus of functional programming?

    a) Managing state changes

    b) Iterative algorithms

    c) Declarative programming

    d) Object instantiation

    Answer: c


50. Which of the following is a disadvantage of using recursion in functional programming?

    a) Recursion leads to more readable code

    b) Recursion can lead to stack overflow errors

    c) Recursion allows for easier parallelization

    d) Recursion doesn't allow for tail call optimization

    Answer: b




-- Code With VDK

Tags

Post a Comment

0 Comments
* Please Don't Spam Here. All the Comments are Reviewed by Admin.

#buttons=(Ok, Go it!) #days=(20)

Our website uses cookies to enhance your experience. Learn More
Ok, Go it!