ads

Functional Programming MCQ

 

Functional Programming MCQ - part 2






1. Which programming paradigm emphasizes the use of mathematical functions?

   a) Functional programming

   b) Imperative programming

   c) Object-oriented programming

   d) Procedural programming

   Answer: a


2. What is a key characteristic of pure functions?

   a) They have side effects

   b) They rely on mutable state

   c) They always produce the same output for a given input

   d) They can modify global variables

   Answer: c


3. Which of the following is an example of an impure function?

   a) Addition of two numbers

   b) Printing a value to the console

   c) Finding the square root of a number

   d) Sorting a list of integers

   Answer: b


4. What does recursion refer to in programming?

   a) A looping construct

   b) A function that calls itself

   c) A method for handling exceptions

   d) A process of converting data types

   Answer: b


5. What is a higher-order function?

   a) A function that returns a function

   b) A function that takes another function as an argument

   c) A function that operates on global variables

   d) A function with no return value

   Answer: b


6. Which programming paradigm typically relies on statements and commands for execution?

   a) Functional programming

   b) Imperative programming

   c) Declarative programming

   d) Object-oriented programming

   Answer: b


7. What is the primary focus of functional programming?

   a) Managing state changes

   b) Executing commands sequentially

   c) Declarative programming

   d) Instantiating objects

   Answer: c


8. Which of the following is a characteristic of scripting languages?

   a) They are compiled before execution

   b) They are primarily used for low-level system programming

   c) They are often interpreted rather than compiled

   d) They do not support functions

   Answer: c


9. What is currying in functional programming?

   a) A process of concatenating strings

   b) A process of converting a function with multiple arguments into a sequence of functions

   c) A process of optimizing recursive functions

   d) A process of converting imperative code into functional code

   Answer: b


10. What is functional composition?

    a) Combining multiple functions to create a new function

    b) Modifying the behavior of existing functions

    c) Creating loops within functional code

    d) Implementing object-oriented principles in functional code

    Answer: a


11. Which of the following is a benefit of functional programming?

    a) Increased reliance on mutable state

    b) Improved readability of code

    c) Difficulty in reasoning about code

    d) Limited support for recursion

    Answer: b


12. In functional programming, what does the term "application" refer to?

    a) Executing a script

    b) Passing arguments to a function

    c) Creating an instance of an object

    d) Defining variables

    Answer: b


13. Which of the following statements is true about pure functions?

    a) They can have side effects

    b) They are difficult to test and debug

    c) They always produce the same output for the same input

    d) They rely heavily on mutable state

    Answer: c


14. What is the primary goal of functional programming languages?

    a) Efficient memory management

    b) Managing state changes

    c) Emphasizing declarative programming

    d) Encapsulating data within objects

    Answer: c


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

    a) Mutable state

    b) First-class functions

    c) Immutability

    d) Higher-order functions

    Answer: a


16. What is the purpose of recursion in functional programming?

    a) To replace loops and iterations

    b) To simplify the syntax of programs

    c) To allow for state changes

    d) To handle exceptions gracefully

    Answer: a


17. Which of the following is an example of a higher-order function?

    a) Sorting a list of integers

    b) Adding two numbers together

    c) Mapping a function over a list

    d) Finding the length of a string

    Answer: c


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

    a) Ease of testing and debugging

    b) Avoidance of side effects

    c) Ability to modify global state

    d) Improved code maintainability

    Answer: c


19. What is the primary advantage of using currying in functional programming?

    a) Reducing the need for recursion

    b) Simplifying the syntax of programs

    c) Allowing for partial application of functions

    d) Enabling the use of imperative constructs

    Answer: c


20. What is a common use case for functional composition?

    a) Concatenating strings

    b) Creating loops

    c) Modifying global variables

    d) Building complex functions from simpler ones

    Answer: d


21. Which of the following is a characteristic of imperative programming languages?

    a) Emphasis on immutable data

    b) Use of mathematical functions

    c) Focus on how to achieve a result

    d) Declarative syntax

    Answer: c


22. Which of the following is NOT a characteristic of pure functions?

    a) They always produce the same output for the same input

    b) They have no side effects

    c) They rely on mutable state

    d) They are deterministic

    Answer: c


23. What does it mean for a function to be impure?

    a) It always produces the same output for the same input

    b) It relies on mutable state or has side effects

    c) It can be called multiple times without changing the result

    d) It only operates on immutable data

    Answer: b


24. In functional programming, what is the primary focus when defining functions?

    a) How to execute a sequence of commands

    b) Managing mutable state

    c) What the function should compute

    d) Instantiating objects

    Answer: c


25. Which of the following statements is true about recursion?

    a) It always leads to better performance compared to iterative solutions

    b) It allows functions to call themselves indefinitely

    c) It can replace all forms of iteration

    d) It may lead to stack overflow errors if not properly managed

    Answer: d


26. What is a characteristic of higher-order functions?

    a) They can only accept primitive data types as arguments

    b) They always return a function

    c) They can accept functions as arguments and/or return functions as results

    d) They cannot be passed as arguments to other functions

    Answer: c


27. Which of the following best describes the concept of functional application?

    a) The process of applying a function to each


 element of a collection

    b) The process of defining a new function based on existing ones

    c) The process of passing arguments to a function

    d) The process of executing a script

    Answer: c


28. What is the primary advantage of using pure functions?

    a) They can have side effects

    b) They are easier to test and debug

    c) They rely heavily on mutable state

    d) They are more difficult to reason about

    Answer: b


29. What is the primary purpose of currying in functional programming?

    a) To convert imperative code to functional code

    b) To reduce the need for recursion

    c) To simplify function definitions with multiple arguments

    d) To improve the performance of higher-order functions

    Answer: c


30. What is the primary focus of functional programming languages?

    a) Managing state changes

    b) Executing commands sequentially

    c) Declarative programming

    d) Instantiating objects

    Answer: c


31. Which of the following is a characteristic of functional composition?

    a) Combining multiple functions to create a new function

    b) Modifying the behavior of existing functions

    c) Creating loops within functional code

    d) Implementing object-oriented principles in functional code

    Answer: a


32. Which programming paradigm relies heavily on mutable state and imperative commands?

    a) Functional programming

    b) Declarative programming

    c) Imperative programming

    d) Object-oriented programming

    Answer: c


33. What is the primary goal of functional programming languages?

    a) Efficient memory management

    b) Managing state changes

    c) Emphasizing declarative programming

    d) Encapsulating data within objects

    Answer: c


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

    a) Mutable state

    b) First-class functions

    c) Immutability

    d) Higher-order functions

    Answer: a


35. Which of the following is a characteristic of imperative programming languages?

    a) Emphasis on immutable data

    b) Use of mathematical functions

    c) Focus on how to achieve a result

    d) Declarative syntax

    Answer: c


36. Which of the following is NOT a characteristic of pure functions?

    a) They always produce the same output for the same input

    b) They have no side effects

    c) They rely on mutable state

    d) They are deterministic

    Answer: c


37. What does it mean for a function to be impure?

    a) It always produces the same output for the same input

    b) It relies on mutable state or has side effects

    c) It can be called multiple times without changing the result

    d) It only operates on immutable data

    Answer: b


38. In functional programming, what is the primary focus when defining functions?

    a) How to execute a sequence of commands

    b) Managing mutable state

    c) What the function should compute

    d) Instantiating objects

    Answer: c


39. Which of the following statements is true about recursion?

    a) It always leads to better performance compared to iterative solutions

    b) It allows functions to call themselves indefinitely

    c) It can replace all forms of iteration

    d) It may lead to stack overflow errors if not properly managed

    Answer: d


40. What is a characteristic of higher-order functions?

    a) They can only accept primitive data types as arguments

    b) They always return a function

    c) They can accept functions as arguments and/or return functions as results

    d) They cannot be passed as arguments to other functions

    Answer: c



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!