My Report

C Variables Test – 2


Correct Answer: 2 points | Wrong: -1 point
Grades: A* (100% score) | A (80%-99%) | B (60%-80%) | C (40%-60%) | D (0%-40%)
advertisement

1. What will be the output of the following C code?

    #include <stdio.h>
    int i;
    int main()
    {
        extern int i;
        if (i == 0)
            printf("scope rules\n");
    }

2. Which variable has the longest scope in the following C code?

    #include <stdio.h>
    int b;
    int main()
    {
        int c;
        return 0;
    }
    int a;
    

3. Comment on the output of the following C code.

    #include <stdio.h>
    int main()
    {
        int i;
        for (i = 0;i < 5; i++)
        int a = i;
        printf("%d", a);
    }

4. What is the scope of a function?

5. What will be the output of the following C code (without linking the source file in which ary1 is defined)?

    #include <stdio.h>
    int main()
    {
        extern ary1[];
        printf("scope rules\n");
    }

6. Comment on the following 2 C programs.

    #include <stdio.h> //Program 1
    int main()
    {
        int a;
        int b;
        int c;
    }
 
   #include <stdio.h> //Program 2
    int main()
    {
        int a;
        {
            int b;
        }
        {
            int c;
        }
    }

7. What is the scope of an external variable?

8. What will be the output of the following C code (after linking to source file having definition of ary1)?

    #include <stdio.h>
    int main()
    {
        extern ary1[];
        printf("%d\n", ary1[0]);
    }

 

Start practicing “1000 MCQs on C”, and once you are ready, you can take tests on all topics by attempting our “C Test Series”.

Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.