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.

advertisement

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

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.

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!

advertisement
advertisement

Leave a Comment

Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He is Linux Kernel Developer & SAN Architect and is passionate about competency developments in these areas. He lives in Bangalore and delivers focused training sessions to IT professionals in Linux Kernel, Linux Debugging, Linux Device Drivers, Linux Networking, Linux Storage, Advanced C Programming, SAN Storage Technologies, SCSI Internals & Storage Protocols such as iSCSI & Fiber Channel. Stay connected with him @ LinkedIn | Youtube | Instagram | Facebook | Twitter

Check his free tutorial videos on Advanced C Programming. Join his Sanfoundry-Classes telegram channel for all videos and queries on Programming, Data-Structures, Kernel, Personality development and Mentoring.