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
Answer: c
Clarification: 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
Answer: a
Clarification: 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
Answer: b
Clarification: In the external linkage, it is used to refer to identifiers in various programs.
4. What will be the output of the following C++ codes?
i.
-
#ifndef Exercise_H -
#define Exercise_H -
int number = 842;
-
#endif
ii.
-
#include -
#include "exe.h" -
using namespace std;
-
int main(int argc, char * argv[] )
-
{ -
cout << number++;
-
return 0;
-
}
a) 842
b) 843
c) compile time error
d) 845
Answer: a
Clarification: 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:
$ 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
Answer: b
Clarification: external is the default type of linkage that is available for identifiers.
6. To use external linkage we have to use which keyword?
a) static
b) extern
c) const
d) argc
Answer: b
Clarification: 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
Answer: c
Clarification: 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
Answer: c
Clarification: None.
Global Education & Learning Series – C++ Programming Language.
