C | Variable Declaration and Scope | Question 4
#include <stdio.h> extern int var = 0; int main() { var = 10; printf("%d ", var); return 0; } |
chevron_right
filter_none
(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.
Refer: Understanding “extern” keyword in C
Quiz of this Question
Recommended Posts:
- C | Variable Declaration and Scope | Question 5
- C | Variable Declaration and Scope | Question 8
- C | Variable Declaration and Scope | Question 7
- C | Variable Declaration and Scope | Question 6
- C | Variable Declaration and Scope | Question 3
- C | Variable Declaration and Scope | Question 2
- C | Variable Declaration and Scope | Question 1
- Can we access global variable if there is a local variable with same name?
- Scope rules in C
- Scope Resolution Operator Versus this pointer in C++?
- What happens when a function is called before its declaration in C?
- What is the difference between single quoted and double quoted declaration of char array?
- How to print a variable name in C?
- Variable Length Arrays in C and C++
- Variable Length Argument in C



