C Programming Questions and Answers – External Variables – 2

«
»
Sanfoundry’s 1000+ Interview Questions & Answers on C helps anyone preparing for Cognizant and other companies C interviews. One should practice these 1000+ interview questions and answers continuously for 2-3 months to clear Cognizant interviews on C Programming language.

Here is a listing of basic C interview questions on “External Variable” along with answers, explanations and/or solutions:

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

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

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?

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

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