Home » C Programming » Variables » Question
  1. What will be the output of the following C code?
     #include <stdio.h>
    void main()
    {
    A();
    printf("%d", n);
    }
    int n;
    void A()
    {
    n = 10;
    }
    1. 10
    2. 0
    3. Compilation Error
    4. Depend on compiler
    5. None of these
Correct Option: C

Compilation Error

main.c: In function ‘main’:
main.c:4:9: warning: implicit declaration of function ‘A’ [-Wimplicit-function-declaration]
A();
^
main.c:5:22: error: ‘n’ undeclared (first use in this function)
printf("%d", n);
^
main.c:5:22: note: each undeclared identifier is reported only once for each function it appears in
main.c: At top level:
main.c:8:10: warning: conflicting types for ‘A’
void A()
^
main.c:4:9: note: previous implicit declaration of ‘A’ was here
A();
^



Your comments will be displayed only after manual approval.