MCQ Bank
The operator to free the allocated memory using new operator is ________________.
- A) del
- B) free
- C) remove
- D) delete
The memory allocation in C++ is carried out with the help of _______________.
- A) dot operator
- B) new operator
- C) NULL pointer
- D) + operator
Where should delete typically be called to deallocate memory allocated in a constructor?
- A) In another member function.
- B) In the main program.
- C) In the destructor
- D) Immediately after new.
What will be the output of following statement?
cout << setfill(‘0’) << setw(7) << 128 ;
- A) 1280000
- B) 0128128
- C) 0000128
- D) 0012800
____________will return the number of bytes reserved for a variable or data type.
- A) void pointer
- B) new operator
- C) sizeof operator
- D) free operator
Which of the following is normally a source for cin stream?
- A) Printer
- B) Variable
- C) Keyboard
- D) Constant
i+=2 is equivalent to ___________.
- A) i=i++;
- B) 2+=I;
- C) i=i+2;
- D) i=1+I;
How does new in C++ differ from malloc()?
- A) new is a function, while malloc is an operator
- B) new calls the constructor, malloc does not
- C) new requires manual size calculation with sizeof
- D) new returns a void* pointer
Why is malloc() discouraged in C++ for objects?
- A) It cannot allocate memory.
- B) It only works with primitive types.
- C) It does not call constructors/destructors
- D) It is slower than new.
For the joining of two strings in string class, we may use “+” operator, can we use “-” operator the same way for subtracting strings?
- A) Yes
- B) No
- C) Yes along “+” operator only
- D) Yes along “:?” operator only
If class A is a friend of class B, and class B is a friend of class C. If class A wants class C to be a friend, __________________
- A) it has to declare , class A as a friend
- B) it has to declare, class C as a friend
- C) it has to declare, class B as a friend
- D) it has to declare, class B and class A as friend classes
Which of the following is a destination of cout stream?
- A) Constant
- B) Data type
- C) Variable
- D) Printer
Which statement is true about the following code in C++? int &j = i;
- A) The value of variable i is assigned to the variable j
- B) The address of variable i is assigned to the variable j
- C) j is a synonym of variable i
- D) The address of variable j is assigned to the variable i
Once an object is declared as a friend, _________________________.
- A) it has no access to data members of the class
- B) it has access to public members only
- C) it has access to protected data members only
- D) it has access to all non-public members as if they were public
The return type of the overloaded new operator must be?
- A) void (nothing)
- B) void pointer
- C) object pointer
- D) int pointer
The ws manipulator can be used with ______ stream(s).
- A) Input
- B) None of the given options
- C) Input/Output
- D) Output
In C language, the region of memory allocated at runtime is called _______________.
- A) available memory
- B) heap
- C) free store
- D) stack
Suppose we have a data member buf of our String class and we like to refer it in a member function of the same class, then choose which option is incorrect?
- A) (*this).buf
- B) this.(*buf)
- C) buf
- D) this -> buf
Which of the following syntax is best used to delete an array of 5 objects named ‘string’ allocated using new operator.
- A) delete []string ;
- B) delete string[5] ;
- C) delete string ;
- D) delete string[] ;
Overloaded member operator function is always called by _______
- A) Class
- B) Object
- C) Primitive data type
- D) Compiler