C++ Programming Questions and Answers – Linkage

C++ questions and puzzles focuses on “Linkage”. One shall practice these questions and puzzles to improve their C++ programming skills needed for various interviews walk-in interviews, interviews, 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.

C++ questions and puzzles on “Linkage” along with answers, explanations and/or solutions:

Q 1. How many types of linkages are there in C++?
A. 1
B. 2
C. 3
D. 4

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

Q 2. To use internal linkage we have to use which keyword?
A. extern
B. static
C. static or extern
D. public

Show Answer Answer:-B. static
Explanation static keyword is used for internal linkage.

Q 3. Which one is used to refer to program elements in any translation units?
A. external linkage
B. internal linkage
C. no linkage
D. internal & external linkage

Show Answer Answer:-A. external linkage
Explanation In the external linkage, it is used to refer to identifiers in various programs.

Q 4. What will be the output of the following C++ codes?
i. #ifndef Exercise_H

#define Exercise_H

int number = 842;

#endif

ii.#include <iostream>

#include “exe.h”

using namespace std;

int main(int argc, char * argv[] )

{

cout << number++;

return 0;

}

A. 840
B. 841
C. compile time error
D. 842

Show Answer Answer:-D. 842
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: $ g++ link.cpp $ a.out 842

Q 5. What is the default type of linkage that is available for identifiers?
A. internal
B. external
C. no linkage
D. single linkage

Show Answer Answer:-B. external
Explanation external is the default type of linkage that is available for identifiers.

Q 6. To use external linkage we have to use which keyword?
A. static
B. argc
C. const
D. extern

Show Answer Answer:-D. extern
Explanation Extern keyword is used to represent identifiers from other programs.

Q 7. Which is used to use a function from one source file to another?
A. prototype
B. declaration
C. code
D. variable

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

Q 8. What is the use of no linkage?
A. make the entity visible to other programs
B. make the entity visible only to that block
C. make the entity visible to other blocks in the same program
D. make the entity invisible

Show Answer Answer:-B. make the entity visible only to that block
Explanation None.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

You cannot copy content of this page