CBSE Class 12 Computer Science
Question 64 of 103
Working with Functions — Question 11
Back to all questions| Local variable | Global variable |
|---|---|
| A local variable is a variable defined within a function. | A global variable is a variable defined in the 'main' program. |
| They are only accessible within the block in which they are defined. | They are accessible from anywhere within the program, including inside functions. |
| These variables have local scope. | These variables have global scope. |
| The lifetime of a local variable is limited to the block of code in which it is defined. Once the execution exits that block, the local variable is destroyed, and its memory is released. | Global variables persist throughout the entire execution of the program. They are created when the program starts and are only destroyed when the program terminates. |