Question:medium

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: Feb 18, 2026
  • creating reusable code blocks
  • documenting the code
  • testing the code
  • coding of conditional statements
Show Solution

The Correct Option is A

Solution and Explanation

Step 1: Define a programming function.
A function is a discrete code segment designed to execute a specific task. It can be called from other parts of the program.

Step 2: Analyze the advantages of functions. 
The primary advantages are modularity and code reuse. By encapsulating a task, the function can be executed repeatedly by simply calling it, avoiding code duplication. This adheres to the DRY (Don't Repeat Yourself) principle and enhances code readability, maintainability, and debugging.

Step 3: Evaluate the options. 
(A) The main purpose is "creating reusable code blocks." Code is written once within the function and then used multiple times. 

(B), (C), (D): While documenting, testing, and using conditional statements are programming activities, they aren't a function's primary objective. Functions benefit from documentation and testing, and frequently incorporate conditional statements, but their central function is to encapsulate and reuse logic.

Was this answer helpful?
0


Questions Asked in CUET (PG) exam