The correct answer is TRUE.
A variable is scoped to a global or local variable depending on how it is declared. A global variable is accessible from anywhere in the program, while a local variable is only accessible within the function in which it is declared.
For example, the following code defines a global variable named x
:
int x = 10;
The variable x
can be accessed from anywhere in the program, such as in the following function:
void foo() {
printf("%d\n", x);
}
The following code defines a local variable named y
:
void foo() {
int y = 20;
printf("%d\n", y);
}
The variable y
can only be accessed within the function foo()
. If you try to access y
from outside of foo()
, you will get an error.
In general, it is a good practice to declare variables as local variables whenever possible. This will help to prevent errors and make your code more readable.