engineering computer science MCQ #1240

What is the difference between a local variable and a global variable?

engineering computer science MCQ #1240

  1. Question 1

    Q1. What is the difference between a local variable and a global variable?

    • A) A local variable is accessible throughout the program, while a global variable is accessible only within a specific scope
    • B) A local variable is accessible only within a specific scope, while a global variable is accessible throughout the program
    • C) A local variable is used for dynamic memory allocation, while a global variable is used for static memory allocation
    • D) A local variable is used for static memory allocation, while a global variable is used for dynamic memory allocation

    Answer: A local variable is accessible only within a specific scope, while a global variable is accessible throughout the program

    Explanation: A local variable is declared within a specific scope and is accessible only within that scope, while a global variable is declared outside any scope and is accessible throughout the program.