Skip to content
Related Articles

Related Articles

Improve Article

C | Variable Declaration and Scope | Question 2

  • Difficulty Level : Basic
  • Last Updated : 28 Jun, 2021

Predict the output




#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.

Quiz of this Question

Want to learn from the best curated videos and practice problems, check out the C Foundation Course for Basic to Advanced C.
My Personal Notes arrow_drop_up
Recommended Articles
Page :