C Programming Questions and Answers – External Variables – 2

«
»

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

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.     double i;
  3.     int main()
  4.     {
  5.        printf("%g\n",i);
  6.        return 0;
  7.     }

a) 0
b) 0.000000
c) Garbage value
d) Depends on the compiler
View Answer

Answer: a
Explanation: None.

2. Which part of the program address space is p stored in the following C code?

Sanfoundry Certification Contest of the Month is Live. 100+ Subjects. Participate Now!
advertisement
advertisement
advertisement
  1.     #include <stdio.h>
  2.     int *p = NULL;
  3.     int main()
  4.     {
  5.         int i = 0;
  6.         p = &i;
  7.         return 0;
  8.     }

a) Code/text segment
b) Data segment
c) Bss segment
d) Stack
View Answer

Answer: b
Explanation: None.
advertisement

3. Which part of the program address space is p stored in the following C code?

  1.     #include <stdio.h>
  2.     int *p;
  3.     int main()
  4.     {
  5.         int i = 0;
  6.         p = &i;
  7.         return 0;
  8.     }

a) Code/text segment
b) Data segment
c) Bss segment
d) Stack
View Answer

Answer: c
Explanation: None.
advertisement

4. Can variable i be accessed by functions in another source file?

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

a) Yes
b) No
c) Only if static keyword is used
d) Depends on the type of the variable
View Answer

Answer: a
Explanation: None.

5. Property of the external variable to be accessed by any source file is called by the C90 standard as __________
a) external linkage
b) external scope
c) global scope
d) global linkage
View Answer

Answer: a
Explanation: None.

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

  1.     #include <stdio.h>
  2.     int *i;
  3.     int main()
  4.     {
  5.         if (i == NULL)
  6.             printf("true\n");
  7.         return 0;
  8.     }

a) true
b) true only if NULL value is 0
c) Compile time error
d) Nothing
View Answer

Answer: a
Explanation: None.

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

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

a) true
b) true only if NULL value is 0
c) Compile time error
d) Nothing
View Answer

Answer: b
Explanation: None.

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

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

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

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

advertisement
advertisement

Leave a Comment

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 & technical discussions at Telegram SanfoundryClasses.