0% found this document useful (0 votes)
8 views5 pages

C++ CBT Practice Questions

The document contains a series of C++ practice questions and answers covering various topics such as functions, pointers, classes, and object-oriented programming concepts. Key concepts include function declarations, memory allocation, encapsulation, inheritance, and polymorphism. It serves as a study guide for individuals preparing for C++ programming assessments.

Uploaded by

Yasir Idris
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views5 pages

C++ CBT Practice Questions

The document contains a series of C++ practice questions and answers covering various topics such as functions, pointers, classes, and object-oriented programming concepts. Key concepts include function declarations, memory allocation, encapsulation, inheritance, and polymorphism. It serves as a study guide for individuals preparing for C++ programming assessments.

Uploaded by

Yasir Idris
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

C++ CBT Practice Questions and Answers

46. Which keyword is used to define a function in C++?

Answer: D. No keyword

47. Which function must every C++ program have?

Answer: C. main()

48. Which is the correct way to declare a function returning int?

Answer: A. int func();

49. Which keyword ends the function and returns a value?

Answer: C. return

50. What is the output?

int add(int x, int y) { return x + y; }

cout << add(3, 4);

Answer: A. 7

51. A function with the same name but different parameters is called?

Answer: A. Overloading

52. What is a function that calls itself?

Answer: D. Recursive

53. Which function type returns no value?

Answer: B. void

54. What is the output of:

void greet() { cout << "Hi"; }

greet();

Answer: A. Hi

55. What is the scope of a local variable?

Answer: C. Function/block it is declared in


56. Which is a valid function call?

Answer: B. print();

57. Which is not a type of function argument?

Answer: C. Pass by object

58. Default arguments are assigned in:

Answer: D. Both B & C

59. Which header file is needed for math functions like sqrt()?

Answer: D. Both B & C

60. What is the return type of this function?

float area(int r) { return 3.14 * r * r; }

Answer: B. float

61. Which symbol is used to declare a pointer?

Answer: B. *

62. What does & symbol represent in C++?

Answer: B. Address-of

63. What does * symbol represent in pointer context?

Answer: B. Dereferencing

64. Which is a valid pointer declaration?

Answer: B. int *p;

65. What will this print?

int a = 10; int *p = &a;

cout << *p;

Answer: B. 10

66. Which operator is used to access object members using a pointer?

Answer: B. ->
67. Pointers can store:

Answer: B. Addresses

68. What does NULL mean in C++?

Answer: A. 0

69. Which header is required for using NULL?

Answer: D. None required

70. What is a dangling pointer?

Answer: C. Points to a deleted object

71. What is a pointer to a pointer called?

Answer: B. **p

72. Can you assign 0 to a pointer?

Answer: B. Yes

73. Can pointers be used with arrays?

Answer: A. Yes

74. What is the output?

int arr[3] = {1,2,3};

int *p = arr;

cout << *(p+1);

Answer: B. 2

75. Which function allocates memory dynamically?

Answer: D. All of the above

76. Which keyword is used to create a class?

Answer: B. class

77. What is an object?

Answer: A. Instance of a class


78. What is encapsulation?

Answer: A. Hiding data

79. Which is a valid object declaration from class Car?

Answer: A. Car car;

80. Which access specifier makes members public?

Answer: C. public

81. What is inheritance in C++?

Answer: B. Reusing code from base class

82. Which symbol is used for inheritance?

Answer: A. :

83. What is a constructor?

Answer: C. Function called when an object is created

84. What is a destructor?

Answer: B. ~ClassName()

85. Can a class have multiple constructors?

Answer: B. Yes, using overloading

86. What is polymorphism?

Answer: B. Many forms of a function

87. Which is the base class for all C++ classes?

Answer: B. No base class

88. Which keyword is used to define inheritance type?

Answer: A. public

89. What is function overloading?

Answer: A. Same name, different parameters

90. Which feature lets you redefine base class function in derived class?
Answer: C. Overriding

91. Which of the following is a compiler error?

Answer: A. Typo in keyword

92. Which header file handles input/output?

Answer: C. <iostream>

93. What does the cin object do?

Answer: B. Reads input

94. What is the full form of OOP?

Answer: B. Object Oriented Programming

95. Which of the following is not a C++ keyword?

Answer: C. define

96. Which operator is used to create objects dynamically?

Answer: B. new

97. Which of these is used to include a library in C++?

Answer: C. #include

98. Which symbol marks the start of a preprocessor directive?

Answer: A. #

99. What happens if you don't return a value from a non-void function?

Answer: B. Compile-time error

100. What does endl do in C++?

Answer: C. Inserts newline

You might also like