Extern
extern int var;
int main()
{
var = 10;
printf("%d ", var);
return 0;
}
(A) Compiler Error: var is not defined
(B) 20
(C) 0
Answer: (A)
Explanation: var is only declared and not defined (no memory allocated for it)
#include <stdio.h>
int var = 20;
int main()
{
int var = var;
printf("%d ", var);
return 0;
}
(A) Garbage Value
(B) 20
(C) Compiler Error
Answer: (A)
Explanation: First var is declared, then value is assigned to it. As soon as var is declared as a local variable, it hides the global variable var.
#include <stdio.h>
extern int var = 0;
int main()
{
var = 10;
printf("%d ", var);
return 0;
}
(A) 10
(B) Compiler Error: var is not defined
(C) 0
Answer: (A)
Explanation: If a variable is only declared and an initializer is also provided with that declaration, then the memory for that variable will be allocated i.e. that variable will be considered as defined.
0 comments:
Post a Comment