C Programming Questions and Answers – Scope of a Variable – 2

This set of C Multiple Choice Questions & Answers (MCQs) focuses on “Scope of a Variable – 2”.

Pre-requisite for this C MCQ set: Advanced C Programming Video Tutorial.

1. What will be the sequence of allocation and deletion of variables in the following C code?

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

a) a->b, a->b
b) a->b, b->a
c) b->a, a->b
d) b->a, b->a
View Answer

Answer: b
Explanation: None.
advertisement
advertisement

2. Array sizes are optional during array declaration by using ______ keyword.
a) auto
b) static
c) extern
d) register
View Answer

Answer: c
Explanation: None.

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

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

a) 4
b) 3
c) 0
d) Undefined
View Answer

Answer: a
Explanation: None.
advertisement

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

advertisement
  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.     }

a) 8 3
b) 3 8
c) 8 5
d) 5 3
View Answer

Answer: a
Explanation: None.

5. What will be the output of the following 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.     }

a) 0
b) 4
c) Compile time error
d) Undefined
View Answer

Answer: b
Explanation: None.

6. What will be the output of the following 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.     }

a) 9
b) 5
c) 4
d) 0
View Answer

Answer: c
Explanation: None.

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

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

a) 8
b) 0
c) Undefined
d) Compile time error
View Answer

Answer: d
Explanation: None.

Sanfoundry Global Education & Learning Series – C Programming Language.

To practice all areas of C language, here is complete set of 1000+ Multiple Choice Questions and Answers.

If you find a mistake in question / option / answer, kindly take a screenshot and email to [email protected]

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
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.