Variable scope on which a variable does not loose its value when the function exists and use that value if the function is called again is:

  1. Local

  2. function parameter

  3. static

  4. None of above


Correct Option: C

AI Explanation

To answer this question, you need to understand the concept of variable scope in programming.

Option A) Local - This option is incorrect because local variables are only accessible within the scope of the function or block in which they are defined. Once the function exits, the local variable is destroyed, and its value is lost.

Option B) Function parameter - This option is incorrect because function parameters are also considered local variables. Like other local variables, their value is lost once the function exits.

Option C) Static - This option is correct because static variables have a different scope compared to local variables. When a static variable is declared within a function, it retains its value even after the function exits. The value of a static variable is preserved between function calls, allowing it to be accessed and used if the function is called again.

Option D) None of above - This option is incorrect because the correct answer is option C, static.

The correct answer is C) static. This option is correct because static variables do not lose their value when the function exits and can be accessed if the function is called again.

Find more quizzes: