nullptr and dynamic memory management (new, delete) — C++ MCQs

30
Score: 0
Attempted: 0/30
1. What is nullptr in C++?



2. Which of the following is correct to assign nullptr to a pointer?



3. What is the type of nullptr?



4. What does new int; do?



5. How do you deallocate memory allocated by new?



6. How do you allocate an array of 5 integers on heap?



7. How do you free memory allocated for an array?



8. What is the difference between NULL and nullptr?



9. What happens if you delete a nullptr?



10. What is wrong with this code?
int *p = new int;
delete p;
delete p;




11. Which of the following is correct dynamic memory allocation for a double variable?



12. Which operator allocates memory and calls constructor for class objects?



13. Which operator calls destructor and frees memory?



14. What happens if you do not delete dynamically allocated memory?



15. Which is correct way to allocate memory for an array of objects?



16. Can you assign nullptr to any pointer type?



17. What is output?
int *p = nullptr;
if(p) cout << "Not null";
else cout << "Null";




18. Dynamic memory for objects of class is created using?



19. How do you delete a single object dynamically allocated?



20. What happens if delete[] is used on single object allocated by new?



21. How do you dynamically allocate a 2D array?



22. Can nullptr be compared with NULL?



23. What is advantage of nullptr over NULL?



24. Which is correct syntax for new object with constructor?



25. What is wrong with code?
int *p;
delete p;




26. What is correct way to free dynamically allocated 2D array?



27. Which of the following is NOT allowed?



28. Which operator allocates memory but does NOT call constructor?



29. Which of the following is valid initialization of pointer using nullptr?



30. What is correct to prevent memory leak?



Contents Copyrights Reserved By T4Tutorials