A variable declared inside a function is generally known as what?
Options
- A. Global variable
- B. Local variable
- C. Static data member
- D. More than one of the above
- E. None of the above
Quiz Practice:
B. Local variable
Answer: (B) Local variable
A variable declared inside a function is called a local variable because its scope is limited to the function or block in which it is declared.
For example:
void test() { int x = 10; }
Here, x is a local variable. It cannot be directly accessed from another unrelated function.
A global variable, in contrast, is declared outside functions and can have a much wider scope.