Home » C++ Quiz Questions

C++ new and delete operators quiz

This section contains C++ new and delete operators quiz questions and answers with explanations.
Submitted by IncludeHelp, on May 22, 2018

Question 1
What is the correct syntax to declare an integer variable dynamically in C++ programming language?

  1. int *ival = new int (10);
  2. int ival = new int (10);
  3. Both (A) and (B)
  4. None of these

View Answer | Explanation and Discussion


Question 2
What will be the output of the following program?

#include <iostream>
using namespace std;

int main() 
{
	int *ival = new int (10);
	
	cout<<ival<<endl;
	
	return 0;
}
  1. 10
  2. 0
  3. Memory address
  4. None of these

View Answer | Explanation and Discussion


Question 3
Which statement is trust about new operator in C++?

  1. new is an operator which calls the constructor also
  2. new allocates memory at run time and assigns newly allocated memory block’s memory too the pointer
  3. After allocating the memory new operators returns the pointer of the same type
  1. (1) and (2)
  2. (1) and (3)
  3. (2) and (3)
  4. All - (1), (2) and (3)

View Answer | Explanation and Discussion


Question 4
What is the output of the following program?

#include <iostream>
using namespace std;

class sample
{
    public:
	sample()
	{
		cout<<"Hi ";
	}
	~sample()
	{
		cout<<"Bye ";
	}
};

int main() 
{
	sample *obj = new sample();
	delete(obj);
	return 0;
}
  1. Hi Bye
  2. Hi
  3. Bye
  4. No output

View Answer | Explanation and Discussion





Comments and Discussions!

Load comments ↻






Copyright © 2024 www.includehelp.com. All rights reserved.