C | Variable Declaration and Scope | Question 4

filter_none

edit
close

play_arrow

link
brightness_4
code

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

chevron_right


(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

GeeksforGeeks has prepared a complete interview preparation course with premium videos, theory, practice problems, TA support and many more features. Please refer Placement 100 for details

My Personal Notes arrow_drop_up
Article Tags :
Practice Tags :


2


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