Units

### Unit: Scope Of A Variable - Questions and Answers

Practice these Scope Of A Variable under C Programming walk-in interview Questions/ examination questions with best tricks and short cuts with solution. Student (candidate) who want to crack the walk in interview, competitive exams and want to find short cuts and tricks to solve questions on Scope Of A Variable for following purpose.

– Anyone who is wishing to increase their perfect knowledge of Scope Of A Variable of C Programming.
– Anyone who is preparing for aptitude test and increase his in depth aptitude knowledge C Programming specifically Scope Of A Variable.
– Anyone who is preparing for interviews (competitive examinations, govt examinations and bank examinations, off-campus or on campus interviews, walk-in interview and company interviews) having questions on Scope Of A Variable under C Programming.

– Anyone who is preparing for aptitude test or competitive exam or entrance exam.
– Anyone who is preparing for entrance examinations and other competitive examinations.
– All Experienced, Freshers and Students.

Here is list of Questions and Answers covering all key area of  Scope Of A Variable topic of C Programming:

1.

What is the output of this C code?

1. `    #include <stdio.h>`
2. `    int x = 5;`
3. `    void main()`
4. `    {`
5. `        int x = 3;`
6. `        m();`
7. `        printf("%d", x);`
8. `    }`
9. `    void m()`
10. `    {`
11. `        x = 8;`
12. `        n();`
13. `    }`
14. `    void n()`
15. `    {`
16. `        printf("%d", x);`
17. `    }`

Explanation:

2.

What is the output of this C code after linking with source file having definition of ary1?

1. `    #include <stdio.h>`
2. `    int main()`
3. `    {`
4. `        extern ary1[];`
5. `        printf("%d\n", ary1[0]);`
6. `    }`

Explanation:

3.

Which variable has the longest scope?

1. `    #include <stdio.h>`
2. `    int b;`
3. `    int main()`
4. `    {`
5. `        int c;`
6. `        return 0;`
7. `    }`
8. `    int a;`

Explanation:

4.

What is the output of this C code?

1. `    #include <stdio.h>`
2. `    void main()`
3. `    {`
4. `        {`
5. `            int x = 8;`
6. `        }`
7. `        printf("%d", x);`
8. `    }`

Explanation:

5.

Comment on the output of this 2 C code?

1. `    #include <stdio.h> //Program 1`
2. `    int main()`
3. `    {`
4. `        int a;`
5. `        int b;`
6. `        int c;`
7. `    }`
8. ```
```
9. `    #include <stdio.h> //Program 2`
10. `    int main()`
11. `    {`
12. `        int a;`
13. `        {`
14. `            int b;`
15. `        }`
16. `        {`
17. `            int c;`
18. `        }`
19. `    }`

Explanation:

6.

What is the output of this C code (without linking the source file in which ary1 is defined)?

1. `    #include <stdio.h>`
2. `    int main()`
3. `    {`
4. `        extern ary1[];`
5. `        printf("scope rules\n");`
6. `    }`

Explanation:

7.

What is the output of this C code?

1. `    #include <stdio.h>`
2. `    static int x = 5;`
3. `    void main()`
4. `    {`
5. `        int x = 9;`
6. `        {`
7. `            x = 4;`
8. `        }`
9. `        printf("%d", x);`
10. `    }`

Explanation:

8.

What is the scope of an external variable?

Explanation:

9.

Array sizes are optional during array declaration by using ______ keyword.

Explanation:

10.

What is the output of this C code?

1. `    #include <stdio.h>`
2. `    int x;`
3. `    void main()`
4. `    {`
5. `        m();`
6. `        printf("%d", x);`
7. `    }`
8. `    void m()`
9. `    {`
10. `        x = 4;`
11. `    }`

Explanation:

11.

What is the scope of a function?

Explanation:

12.

What is the output of this C code?

1. `    #include <stdio.h>`
2. `    void main()`
3. `    {`
4. `        int x = 3;`
5. `        {`
6. `            x = 4;`
7. `            printf("%d", x);`
8. `        }`
9. `    }`

Explanation:

13.

Comment on the output of this C code?

1. `    #include <stdio.h>`
2. `    int main()`
3. `    {`
4. `        int i;`
5. `        for (i = 0;i < 5; i++)`
6. `        int a = i;`
7. `        printf("%d", a);`
8. `    }`

Explanation:

14.

The sequence of allocation and deletion of variables for the following code is.

1. `    #include <stdio.h>`
2. `    int main()`
3. `    {`
4. `        int a;`
5. `        {`
6. `            int b;`
7. `        }`
8. `    }`

Explanation:

15.

What is the output of this C code?

1. `    #include <stdio.h>`
2. `    int i;`
3. `    int main()`
4. `    {`
5. `        extern int i;`
6. `        if (i == 0)`
7. `            printf("scope rules\n");`
8. `    }`