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?
- int *ival = new int (10);
- int ival = new int (10);
- Both (A) and (B)
- None of these
View Answer |
Explanation and Discussion
Answer: 1
int *ival = new int (10);
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;
}
- 10
- 0
- Memory address
- None of these
View Answer |
Explanation and Discussion
Question 3
Which statement is trust about new operator in C++?
- new is an operator which calls the constructor also
- new allocates memory at run time and assigns newly allocated memory block’s memory too the pointer
- After allocating the memory new operators returns the pointer of the same type
- (1) and (2)
- (1) and (3)
- (2) and (3)
- All - (1), (2) and (3)
View Answer |
Explanation and Discussion
Answer: 4
All - (1), (2) and (3)
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;
}
- Hi Bye
- Hi
- Bye
- No output
View Answer |
Explanation and Discussion