C | Variable Declaration and Scope | Question 2
Predict the output
#include <stdio.h> int var = 20; int main() { int var = var; printf("%d ", var); return 0; } |
chevron_right
filter_none
(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.
Quiz of this Question
Recommended Posts:
- C | Variable Declaration and Scope | Question 4
- C | Variable Declaration and Scope | Question 7
- C | Variable Declaration and Scope | Question 1
- C | Variable Declaration and Scope | Question 8
- C | Variable Declaration and Scope | Question 3
- C | Variable Declaration and Scope | Question 6
- C | Variable Declaration and Scope | Question 5
- 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?
- Why variable name does not start with numbers in C ?
- Different ways to initialize a variable in C/C++



