Question:

What is the primary purpose of a function?

Show Hint

Think of a function as a recipe. You write the recipe (the function) once. Then, anytime you want to make that dish, you just follow the recipe (call the function) instead of figuring it all out from scratch again.
Updated On: Sep 23, 2025
  • creating reusable code blocks
  • documenting the code
  • testing the code
  • coding of conditional statements
Hide Solution
collegedunia
Verified By Collegedunia

The Correct Option is A

Solution and Explanation

Step 1: Define a function in programming. 
A function is a self-contained block of code that performs a specific task. It can be "called" or "invoked" from other parts of the program.

Step 2: Analyze the benefits of using functions. 
The main benefit is modularity and reusability. By encapsulating a task within a function, you can execute that task multiple times by simply calling the function, without having to rewrite the same code. This principle is known as DRY (Don't Repeat Yourself). It also makes code easier to read, maintain, and debug.

Step 3: Evaluate the options. 
(A) "Creating reusable code blocks" is the core purpose. You write the code once inside the function and can use it many times. 

(B), (C), (D): Documenting, testing, and using conditional statements are all activities related to programming, but they are not the primary purpose of a function itself. Functions should be documented and tested, and they often contain conditional statements, but their main role is to encapsulate and reuse logic.

Was this answer helpful?
0
0

Questions Asked in CUET PG exam

View More Questions