Variables


  1. The name of the variable used in one function cannot be used in another function.











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: C

    Since the scope of the variable declared within a function is restricted only within that function, the same name can be used to declare another variable in another function.


  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. View Hint View Answer Discuss in Forum

    NA

    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();
    ^



  1. Can variable p be accessed by functions in another source file?
    #include <stdio.h>
    int p;
    int main()
    {
    printf("%d\n", p);
    }











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: B

    Yes


  1. What will be the output of the following C code?
    #include <stdio.h>
    int num = 10;
    void main()
    {
    int num = 5;
    printf("%d ", num);
    {
    num = 6;
    }
    printf("%d", num);
    }











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: D

    5 6



  1. What will be the output of the following C code?
    #include <stdio.h>
    int n = 15;
    void main()
    {
    int n = 5;
    printf("%d ", n);
    {
    int n = 10;
    }
    printf("%d", n);
    }











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: E

    5 5