πŸ“Š CPP Programming
Q. In C++, const qualifier can be applied to
1) Member functions of a class
2) Function arguments
3) To a class data member which is declared as static
4) Reference variables
  • (A) Only 1, 2 and 3
  • (B) Only 1, 2 and 4
  • (C) All
  • (D) Only 1, 3 and 4
πŸ’¬ Discuss
βœ… Correct Answer: (C) All
πŸ“Š CPP Programming
Q. How to create a dynamic array of pointers (to integers) of size 10 using new in C++? Hint: We can create a non-dynamic array using int *arr[10]
  • (A) int *arr = new int *[10];
  • (B) int **arr = new int *[10];
  • (C) int *arr = new int [10];
  • (D) Not Possible
πŸ’¬ Discuss
βœ… Correct Answer: (B) int **arr = new int *[10];
πŸ“Š CPP Programming
Q. Which of the following is true about new when compared with malloc:
1) new is an operator, malloc is a function
2) new calls constructor, malloc doesn’t
3) new returns appropriate pointer, malloc returns void * and pointer needs to typecast to appropriate type.
  • (A) 1 and 3
  • (B) 2 and 3
  • (C) 1 and 2
  • (D) All 1, 2 and 3
πŸ’¬ Discuss
βœ… Correct Answer: (D) All 1, 2 and 3
πŸ“Š CPP Programming
Q. Predict the output?
#include <iostream>
using namespace std;
class Test
{
int x;
Test()
{
x = 5;
} };
int main()
{
Test *t = new Test;
cout << t->x;
}
  • (A) Compiler Error
  • (B) 5
  • (C) Garbage Value
  • (D) 0
πŸ’¬ Discuss
βœ… Correct Answer: (A) Compiler Error
πŸ“Š CPP Programming
Q. Is it fine to call delete twice for a pointer?
#include<iostream>
using namespace std;
int main()
{
int *ptr = new int;
delete ptr;
delete ptr;
return 0;
}
  • (A) Yes
  • (B) No
  • (C) none
  • (D) all
πŸ’¬ Discuss
βœ… Correct Answer: (B) No
πŸ“Š CPP Programming
Q. When the inheritance is private, the private methods in base class are __________ in the derived class (in C++).
  • (A) inaccessible
  • (B) accessible
  • (C) protected
  • (D) public
πŸ’¬ Discuss
βœ… Correct Answer: (A) inaccessible
πŸ“Š CPP Programming
Q. What happens when delete is used for a NULL pointer?
int *ptr = NULL;
delete ptr;
  • (A) Compiler Error
  • (B) Run-time Crash
  • (C) No Error
  • (D) None
πŸ’¬ Discuss
βœ… Correct Answer: (C) No Error
πŸ“Š CPP Programming
Q. Which of the following is true about virtual functions in C++?
  • (A) Virtual functions are functions that can be overridden in derived class with the same signature.
  • (B) Virtual functions enable run-time polymorphism in a inheritance hierarchy.
  • (C) If a function is ‘virtual’ in the base class, the most-derived class implementation of the function is called according to the actual type of the object referred to, regardless of the declared type of the pointer or reference. In non-virtual f
  • (D) All of the above
πŸ’¬ Discuss
βœ… Correct Answer: (D) All of the above
πŸ“Š CPP Programming
Q. Which of the following is true about pure virtual functions?
1) Their implementation is not provided in a class where they are declared.
2) If a class has a pure virtual function, then the class becomes abstract class and an
instance of this class cannot be created.
  • (A) Both 1 and 2
  • (B) Only 1
  • (C) Only 2
  • (D) Neither 1 nor 2
πŸ’¬ Discuss
βœ… Correct Answer: (C) Only 2
πŸ“Š CPP Programming
Q. What is the size of wchar_t in C++?
  • (A) 2
  • (B) 4
  • (C) 2 or 4
  • (D) Based on the number of bits in the system
πŸ’¬ Discuss
βœ… Correct Answer: (D) Based on the number of bits in the system

Jump to