hamburger menu
All Coursesall course arrow
adda247
reward-icon
adda247
    arrow
    arrow
    arrow
    ​Which of the following is true regarding Subroutines in a computer program?​
    Question

    Which of the following is true regarding Subroutines in a computer program?

    A.

    Subroutines cannot return a value to the calling program

    B.

    Subroutines can only be called from the main program

    C.

    Subroutines are used to perform repetitive tasks in a program

    D.

    Subroutines can have their own set of local variables

    Correct option is D

    The correct answer is D - Subroutines can have their own set of local variables.

    Subroutines (also called functions, procedures, or methods) are independent blocks of code that can maintain their own local scope with private variables. These local variables exist only within the subroutine's execution context and are automatically created when the subroutine is called and destroyed when it returns. This concept of variable scope is fundamental to modular programming and helps prevent naming conflicts and maintains data encapsulation.

    Important Key Points:

    1. Local Scope: Variables declared inside subroutines are accessible only within that subroutine.
    2. Stack Allocation: Local variables are typically stored on the call stack.
    3. Automatic Lifetime: Local variables are created and destroyed automatically.
    4. Data Encapsulation: Prevents interference between different parts of the program.
    5. Memory Management: Each subroutine call gets its own memory space for local variables.
    6. Variable Shadowing: Local variables can have the same name as global variables without conflict.
    7. Parameter Passing: Subroutines can receive parameters as local variables.

    Knowledge Booster (Incorrect Options):

    ·       Option A is incorrect because subroutines can return values to the calling program using return statements. This is a fundamental feature of functions in most programming languages.

    ·       Option B is incorrect because subroutines can be called from any part of the program, including other subroutines, not just the main program. This enables nested function calls and recursive programming.

    ·       Option C, while often true in practice, is not a defining characteristic of subroutines. Subroutines are used for code organization, reusability, and modularity - not exclusively for repetitive tasks. They can perform any computational task regardless of repetition.

    test-prime-package

    Access ‘Haryana CET Group C’ Mock Tests with

    • 60000+ Mocks and Previous Year Papers
    • Unlimited Re-Attempts
    • Personalised Report Card
    • 500% Refund on Final Selection
    • Largest Community
    students-icon
    194k+ students have already unlocked exclusive benefits with Test Prime!

    Free Tests

    Free
    Must Attempt

    IB ACIO Grade-II Executive (Held on 17 Jan 2024 S1)

    languageIcon English
    • pdpQsnIcon100 Questions
    • pdpsheetsIcon100 Marks
    • timerIcon60 Mins
    languageIcon English
    Free
    Must Attempt

    IB ACIO Grade II Full Mock Test 1

    languageIcon English
    • pdpQsnIcon100 Questions
    • pdpsheetsIcon100 Marks
    • timerIcon60 Mins
    languageIcon English
    Free
    Must Attempt

    General Studies Section Test 1

    languageIcon English
    • pdpQsnIcon20 Questions
    • pdpsheetsIcon20 Marks
    • timerIcon8 Mins
    languageIcon English