C++ Programming Questions and Answers – Linkage

This section on C++ questions and puzzles focuses on “Linkage”. One shall practice these questions and puzzles to improve their C++ programming skills needed for various interviews (campus interviews, walk-in interviews, company interviews), placements, entrance exams and other competitive exams. These programming puzzles can be attempted by anyone focusing on learning C++ programming language. They can be a beginner, fresher, engineering graduate or an experienced IT professional. Our C++ questions come with a detailed explanation of the answers which helps in better understanding of C++ concepts.

Here is a listing of C++ questions and puzzles on “Linkage” along with answers, explanations and/or solutions:

1. How many types of linkages are there in C++?
a) 1
b) 2
c) 3
d) 4
View Answer

Answer: c
Explanation: There are three types of linkage in c++. They are an internal linkage, external linkage, and no linkage.

2. To use internal linkage we have to use which keyword?
a) static
b) extern
c) static or extern
d) public
View Answer

Answer: a
Explanation: static keyword is used for internal linkage.

3. Which one is used to refer to program elements in any translation units?
a) internal linkage
b) external linkage
c) no linkage
d) internal & external linkage
View Answer

Answer: b
Explanation: In the external linkage, it is used to refer to identifiers in various programs.
advertisement
advertisement

4. What will be the output of the following C++ codes?
i.

  1.     #ifndef Exercise_H
  2.     #define Exercise_H
  3.     int number = 842;
  4.     #endif

ii.

Sanfoundry Certification Contest of the Month is Live. 100+ Subjects. Participate Now!
  1.     #include <iostream>
  2.     #include "exe.h"
  3.     using namespace std;
  4.     int main(int argc, char * argv[] )
  5.     {
  6.         cout << number++;
  7.         return 0;
  8.     }

a) 842
b) 843
c) compile time error
d) 845
View Answer

Answer: a
Explanation: In this program, we have created a header file and linked that into the source program and we post incrementing that because of that it is printed as 842.
Output:

advertisement
$ g++ link.cpp
$ a.out
842

5. What is the default type of linkage that is available for identifiers?
a) internal
b) external
c) no linkage
d) single linkage
View Answer

Answer: b
Explanation: external is the default type of linkage that is available for identifiers.
advertisement

6. To use external linkage we have to use which keyword?
a) static
b) extern
c) const
d) argc
View Answer

Answer: b
Explanation: Extern keyword is used to represent identifiers from other programs.

7. Which is used to use a function from one source file to another?
a) code
b) declaration
c) prototype
d) variable
View Answer

Answer: c
Explanation: By defining a function’s prototype in another file means, we can inherit all the features from the source function.

8. What is the use of no linkage?
a) make the entity visible to other programs
b) make the entity visible to other blocks in the same program
c) make the entity visible only to that block
d) make the entity invisible
View Answer

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