read this code: 200+ C++ Programming MCQs | PCBooks - Master C++ Language Online

C++ - Programming MCQ Questions and Answers

Test your knowledge of Microsoft Word with these interactive multiple-choice questions.

« First 4 5 6 7 Last »
« Previous Page Next Page »

81. Which of these is not a valid C++ logical operator?

  • a) &&
  • b) ||
  • c) !
  • d) &|
Answer: D - &| is not a valid operator in C++ (it's sometimes used in other languages).

82. What is the correct syntax to declare a friend function?

  • a) friend void func(); inside class
  • b) void friend func(); inside class
  • c) friend void func() { } inside class
  • d) Both a and b
Answer: D - The friend keyword can appear before or after the return type in the declaration.

83. Which of the following is true about inline functions?

  • a) They must be defined in header files
  • b) They are always faster than regular functions
  • c) They are suggestions to the compiler
  • d) They cannot be recursive
Answer: C - inline is a hint to the compiler, which may ignore it.

84. What is the output of: cout << (7 % 4);

  • a) 1
  • b) 2
  • c) 3
  • d) 4
Answer: C - % is the modulus operator (remainder of 7 divided by 4 is 3).

85. Which of these is not a valid C++17 feature?

  • a) if constexpr
  • b) Structured bindings
  • c) std::filesystem
  • d) Concepts
Answer: D - Concepts were introduced in C++20.

86. What is the purpose of the '[[nodiscard]]' attribute?

  • a) To prevent function inlining
  • b) To warn when return value is ignored
  • c) To disable return value optimization
  • d) To mark functions as pure
Answer: B - [[nodiscard]] warns if a function's return value is ignored.

87. Which STL container provides fastest lookup by key?

  • a) std::vector
  • b) std::map
  • c) std::unordered_map
  • d) std::list
Answer: C - unordered_map provides O(1) average case lookup using hashing.

88. What is the correct way to declare a static member variable?

  • a) static int x; inside class
  • b) int static x; inside class
  • c) static int x; outside class
  • d) Both a and b
Answer: D - static can appear before or after the type in the declaration.

89. Which of these is not a valid C++ type trait?

  • a) std::is_integral
  • b) std::is_class
  • c) std::is_functional
  • d) std::is_pointer
Answer: C - is_functional is not a standard type trait.

90. What is the output of: cout << sizeof(std::string);

  • a) 4
  • b) 8
  • c) 16
  • d) Implementation defined
Answer: D - std::string size depends on the implementation (typically 24-32 bytes).

91. Which of these is not a valid C++20 feature?

  • a) Concepts
  • b) Ranges
  • c) Coroutines
  • d) Reflection
Answer: D - Reflection is planned for future C++ versions.

92. What is the purpose of the '[[likely]]' attribute?

  • a) To mark code paths more likely to execute
  • b) To indicate thread safety
  • c) To force inlining
  • d) To disable optimizations
Answer: A - [[likely]] helps compiler optimize for the expected path.

93. Which STL algorithm is used to count elements?

  • a) std::find
  • b) std::count
  • c) std::search
  • d) std::accumulate
Answer: B - std::count counts elements matching a value.

94. What is the correct way to declare a nested namespace?

  • a) namespace A { namespace B { } }
  • b) namespace A::B { }
  • c) Both a and b
  • d) nested namespace A::B { }
Answer: C - Both syntaxes are valid (the second requires C++17).

95. Which of these is not a valid C++14 feature?

  • a) Binary literals
  • b) Generic lambdas
  • c) Variable templates
  • d) Modules
Answer: D - Modules were introduced in C++20.

96. What is the output of: cout << (10 / 3);

  • a) 3
  • b) 3.333
  • c) 3.0
  • d) 4
Answer: A - Integer division truncates the fractional part.

97. Which of these is not a valid C++ container?

  • a) std::forward_list
  • b) std::flat_map
  • c) std::unordered_set
  • d) std::multimap
Answer: B - flat_map is not in the standard (though available in some libraries).

98. What is the purpose of the '[[no_unique_address]]' attribute?

  • a) To allow empty class optimization
  • b) To prevent address-taking
  • c) To mark singleton classes
  • d) To disable RTTI
Answer: A - It enables empty base optimization for data members.

99. Which STL algorithm is used to merge sorted ranges?

  • a) std::merge
  • b) std::concat
  • c) std::join
  • d) std::combine
Answer: A - std::merge combines two sorted ranges into one sorted range.

100. What is the correct way to declare a deduction guide?

  • a) template<typename T> MyClass(T) -> MyClass<T>;
  • b) MyClass template<T>(T) -> MyClass<T>;
  • c) deduce MyClass(T) -> MyClass<T>;
  • d) template<T> MyClass(T) -> MyClass<T>;
Answer: A - Deduction guides follow template declaration syntax.
« First 4 5 6 7 Last »
« Previous Page Next Page »

Learn Computer Skills with PCBooks

Master computer skills with PCBooks! Explore interactive tutorials, MCQ tests, and online exams for programming, web development, and IT fundamentals. Perfect for beginners and advanced learners.

Online MCQ Tests for Programming

Practice programming MCQ questions and improve your coding skills with our online quizzes. Whether you're learning Python, Java, or C programming, PCBooks has you covered.

Free Web Development Tutorials

Learn HTML, CSS, and JavaScript with our free web development tutorials. Test your knowledge with interactive quizzes and online exams.