MCQs > IT & Programming > C++ > Suppose that a global variable 'x' of type std::atomic with an initializer parameter of 20 should be added to a header and (if necessary) source file so it is available to all files that include it. How should this be implemented where it will cause neither compile nor linker errors when compiling multiple object files together? Assume that a header guard and #include is already present in the header (though not shown in the answers), and that C++11 is enabled.

C++ MCQs

Suppose that a global variable "x" of type std::atomic with an initializer parameter of 20 should be added to a header and (if necessary) source file so it is available to all files that include it. How should this be implemented where it will cause neither compile nor linker errors when compiling multiple object files together? Assume that a header guard and #include is already present in the header (though not shown in the answers), and that C++11 is enabled.

Answer

Correct Answer: In header: extern std::atomic x; In source: std::atomic x(20);

Explanation:

Note: This Question is unanswered, help us to find answer for this one

C++ Skill Assessment

Overall Skill Level-Poor

Your Skill Level: Poor

Retake Quizzes to improve it

search

C++ Skill Assessment

Overall Skill Level-Poor

Your Skill Level: Poor

Retake Quizzes to improve it