C Programming Questions and Answers – External Variables – 1

«
»

This set of C Multiple Choice Questions & Answers (MCQs) focuses on “External Variables – 1”.

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

advertisement

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

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

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

Answer: b
Explanation: None.
advertisement
advertisement

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

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

a) Junk value
b) Run time error
c) 0
d) Undefined
View Answer

Answer: c
Explanation: None.
advertisement

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

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

a) Run time error
b) 3 3
c) 3 5
d) 3 4
View Answer

Answer: d
Explanation: None.
advertisement

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

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

a) 3 3
b) 3 4
c) 3 5
d) Run time error
View Answer

Answer: a
Explanation: None.

5. Functions in C are always _________
a) Internal
b) External
c) Both Internal and External
d) External and Internal are not valid terms for functions
View Answer

Answer: b
Explanation: None.

6. Global variables are ____________
a) Internal
b) External
c) Both Internal and External
d) None of the mentioned
View Answer

Answer: b
Explanation: None.

7. Which of the following is an external variable in the following C code?

  1.     #include <stdio.h>
  2.     int func (int a)
  3.     {
  4.         int b;
  5.         return b;
  6.     }
  7.     int main()
  8.     {
  9.         int c;
  10.         func (c);
  11.     }
  12.     int d;

a) a
b) b
c) c
d) d
View Answer

Answer: d
Explanation: None.

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

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

a) 9
b) 10
c) 11
d) Compile time error
View Answer

Answer: d
Explanation: None.

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

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

a) 5
b) 8
c) Compile time error due to wrong format identifier for double
d) Compile time error due to redeclaration of variable with same name
View Answer

Answer: a
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.