which of the following are true about static variables in C?

  1. Static variables are global variables

  2. static variales have local to the file/Scope they are declared , but exist throught the program life time

  3. static variables are scoped, Meanaing that they will be destroyed once out of scope

  4. Oh come on , Static variales are only in Java , Do not exist in C

  5. static variales have local to the file they are declared , and they will be destroyed once out of scope


Correct Option: B

AI Explanation

To answer this question, let's go through each option to understand why it is correct or incorrect:

Option A) Static variables are global variables - This option is incorrect. Static variables can be declared both globally and locally within a function or block.

Option B) Static variables have local scope to the file/scope they are declared, but exist throughout the program lifetime - This option is correct. When a variable is declared as static, it retains its value between function or block calls. It has local scope to the file or function it is declared in, meaning it can only be accessed within that file or function. However, its lifetime extends throughout the entire program execution.

Option C) Static variables are scoped, meaning that they will be destroyed once out of scope - This option is incorrect. Static variables are not destroyed once out of scope like automatic variables. They retain their value until the program terminates.

Option D) Oh come on, static variables are only in Java. They do not exist in C - This option is incorrect. Static variables also exist in C and function in a similar way to Java.

Option E) Static variables have local scope to the file they are declared, and they will be destroyed once out of scope - This option is incorrect. As mentioned earlier, static variables are not destroyed once out of scope. They persist throughout the program execution.

The correct answer is B) Static variables have local scope to the file/scope they are declared, but exist throughout the program lifetime. This option is correct because static variables retain their value across function or block calls and have local scope to the file or function they are declared in.

Find more quizzes: