Which of the following is not true about Global Variables:
A function that uses global variables does not suffer from reusability.
A global variable is declared outside all functions and is visible to every function in the program. Using globals to pass data between functions has well-known drawbacks (Balagurusamy, Programming in ANSI C).
Statement on inadvertent change: true. A called function can modify a global, so a value the caller relies on can be changed by mistake.
Statement on independence: true. Functions are meant to be independent, isolated modules; a function tied to globals depends on outside state and loses that character.
Statement on readability: true. Since the data is not passed as arguments, a reader cannot see from the call which values the function actually uses.
Statement on reusability: not true. A function that depends on global variables cannot be moved to another program without also carrying those globals, so it does suffer from poor reusability. Claiming it does not suffer is the false statement.
A function that uses global variables does not suffer from reusability. option is correct.
#include <stdio.h>
void func(int i, int j) {
if(i < j) {
int i = 0;
while (i < 10) {
j += 2;
i++;
}
}
printf("%d", i);
}
int main() {
int i = 9, j = 10;
func(i, j);
return 0;
}