MCQ Bank
If we have a program that writes the output data(numbers) to the disc ,and if we collect the output data and write it on the disc in one write operation instead of writing the numbers one by one.
In the above situation the area where we will gather the number is called
- A) Cache
- B) Buffer
- C) Heap
- D) Stack
If we do not write our own assignment operator then which of the following problem may occur?
- A) Unreferenced memory
- B) NULL pointer
- C) Dangling pointer
- D) Memory leak
int &i; It means that i is a _________to an integer.
- A) reference
- B) constant pointer
- C) pointer
- D) data type
Overloaded assignment operator must be
- A) Global function
- B) Non-member function of class
- C) Member function of class
- D) Friend function of class
The friend functions are _____________.
- A) void functions
- B) inline functions
- C) not member of a class
- D) member of a class
When operator function is implemented as member function then return type of function ________.
- A) Must be built-in data type
- B) Must be an object of same class
- C) Can be any data type
- D) Must be user-defined data type
What happens if new fails to allocate memory in C++?
- A) It returns NULL
- B) It returns uninitialized memory
- C) It throws an exception
- D) The program crashes
Let suppose
int a, b, c, d, e;
a = b = c = d = e = 42;
This can be interpreted by the complier as
- A) (a = b = (c = (d = (e = 42))));
- B) a = (b = (c = (d = (e = 42))));
- C) (a = b) = (c = d) = (e = 42);
- D) a = b = (c = (d = (e = 42)));
The friend keyword provides access _______________.
- A) in one direction only
- B) to all classes
- C) in two directions
- D) to the data members of the friend class only
If we use cin stream to read some value and store it in some integer variable and press some alphabet key instead of numeric keys. then what will happen?
- A) Its binary representation will be ignored and the character will be stored
- B) Its binary representation will be ignored and the value will be stored
- C) Its ASCII code will be stored inside the computer
- D) Some error will occur and cin stream will detect this error.
Choose the correct output of the following code in C++. int i =100; int &j = i; j=50; cout<<i++;
- A) 51
- B) 50
- C) 101
- D) 100
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.