C | Variable Declaration and Scope | Question 2

Predict the output

filter_none

edit
close

play_arrow

link
brightness_4
code

#include <stdio.h>
int var = 20;
int main()
{
    int var = var;
    printf("%d ", var);
    return 0;
}

chevron_right


(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



My Personal Notes arrow_drop_up


Article Tags :
Practice Tags :


1


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.