Q2. Ans. Option D
Undefined Variable:->> variable that is accessed in the code but has not been previously declared by that code.
In any scoping result will produce compilation error for undefined variables.
Note:->C uses static(lexical) scoping.
Ex:-foo.c
int main()
{
int y = x;//here x is used without declaration so called undefined variable.
return 0;
}
foo.c: In function `main':
foo.c:2: error: `x' undeclared (first use in this function)
foo.c:2: error: (Each undeclared identifier is reported only once
foo.c:2: error: for each function it appears in.)
https://en.wikipedia.org/wiki/Undefined_variable#C
Another Example
//const int b = 5;
int foo() {
int a = b + 5;
printf("%d",a);
}
int bar() {
int b = 2;
return foo();
}
int main()
{
foo();
bar();
return 0;
}
O/P of Static Scoping :->> Compiler error 'b' is undeclared.
If we remove first line comment then o/p:->> 10,10