#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
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
Recommended Posts:
- C | Variable Declaration and Scope | Question 5
- C | Variable Declaration and Scope | Question 3
- C | Variable Declaration and Scope | Question 2
- C | Variable Declaration and Scope | Question 1
- C | Variable Declaration and Scope | Question 6
- C | Variable Declaration and Scope | Question 7
- C | Variable Declaration and Scope | Question 8
- Can we access global variable if there is a local variable with same name?
- Internal static variable vs. External static variable with Examples in C
- Scope rules in C
- What happens when a function is called before its declaration in C?
- Scope Resolution Operator Versus this pointer in C++?
- What is the difference between single quoted and double quoted declaration of char array?
- How to print a variable name in C?
- How to modify a const variable in C?
- Variable Length Argument in C
- Variable Length Arrays in C and C++
- Why variable name does not start with numbers in C ?
- Different ways to initialize a variable in C/C++
- Redeclaration of global variable in C

