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 2 3 4 5 Last »
« Previous Page Next Page »

41. Which of these is not a valid C++ arithmetic operator?

  • a) +
  • b) *
  • c) ^
  • d) #
Answer: D - # is the preprocessor operator, not an arithmetic operator.

42. What is the correct syntax to declare a namespace in C++?

  • a) namespace MyNamespace { }
  • b) class MyNamespace { }
  • c) package MyNamespace { }
  • d) module MyNamespace { }
Answer: A - Namespaces are declared using the namespace keyword.

43. Which of the following is true about function templates?

  • a) They must have exactly one template parameter
  • b) They generate different functions at compile time
  • c) They cannot be overloaded
  • d) They must return void
Answer: B - Templates generate specialized functions at compile time based on usage.

44. What is the output of: cout << (5 & 3);

  • a) 0
  • b) 1
  • c) 7
  • d) 8
Answer: B - Bitwise AND of 5 (101) and 3 (011) is 1 (001).

45. Which of these is not a valid C++11 smart pointer?

  • a) unique_ptr
  • b) shared_ptr
  • c) auto_ptr
  • d) weak_ptr
Answer: C - auto_ptr is deprecated in C++11.

46. What is the purpose of the 'override' keyword?

  • a) To indicate a function overrides a base class virtual function
  • b) To prevent function overriding
  • c) To optimize virtual function calls
  • d) To create multiple function versions
Answer: A - override explicitly indicates a virtual function override.

47. Which STL container uses a hash table implementation?

  • a) vector
  • b) map
  • c) unordered_map
  • d) set
Answer: C - unordered_map uses hash table implementation.

48. What is the correct way to declare a constant pointer?

  • a) const int *ptr;
  • b) int const *ptr;
  • c) int * const ptr;
  • d) const int const *ptr;
Answer: C - int * const ptr declares a constant pointer to int.

49. Which of these is not a valid C++ cast operator?

  • a) static_cast
  • b) dynamic_cast
  • c) reinterpret_cast
  • d) safe_cast
Answer: D - safe_cast is not a standard C++ cast operator.

50. What is the output of: cout << sizeof("Hello");

  • a) 5
  • b) 6
  • c) 8
  • d) Depends on system
Answer: B - Includes 5 characters plus null terminator.

51. Which of these is not a valid C++11 feature?

  • a) auto keyword
  • b) range-based for loops
  • c) concepts
  • d) nullptr
Answer: C - Concepts were introduced in C++20.

52. What is the purpose of the 'final' keyword?

  • a) To prevent class inheritance
  • b) To prevent method overriding
  • c) Both a and b
  • d) To mark the last element in a container
Answer: C - final can prevent inheritance or overriding.

53. Which STL algorithm is used to reverse a container?

  • a) std::sort
  • b) std::reverse
  • c) std::rotate
  • d) std::flip
Answer: B - std::reverse reverses elements in a range.

54. What is the correct way to declare a lambda function?

  • a) [](int x) { return x * x; }
  • b) lambda(int x) { return x * x; }
  • c) function(int x) { return x * x; }
  • d) auto f = (int x) => x * x;
Answer: A - Lambda syntax uses [] for capture list.

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

  • a) Concepts
  • b) Modules
  • c) Ranges
  • d) Properties
Answer: D - Properties are not part of standard C++20.

56. What is the output of: cout << (5 | 3);

  • a) 1
  • b) 7
  • c) 8
  • d) 15
Answer: B - Bitwise OR of 5 (101) and 3 (011) is 7 (111).

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

  • a) vector
  • b) array
  • c) list
  • d) tuple
Answer: D - tuple is not a container (it's a fixed-size heterogeneous collection).

58. What is the purpose of the 'decltype' keyword?

  • a) To declare variables
  • b) To determine the type of an expression
  • c) To delete types
  • d) To declare template parameters
Answer: B - decltype deduces the type of an expression at compile time.

59. Which STL algorithm is used to find an element?

  • a) std::search
  • b) std::find
  • c) std::locate
  • d) std::get
Answer: B - std::find searches for a value in a range.

60. What is the correct way to declare a thread in C++11?

  • a) std::thread t(function);
  • b) thread t(function);
  • c) new std::thread(function);
  • d) std::thread t = function;
Answer: A - std::thread constructor takes a callable object.
« First 2 3 4 5 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.