Mastering C++
Pointers Practice Questions
Mastering PointersThe questions below are designed to help you get more comfortable working with pointers in C++. Take your time with each one and do your best to complete them fully. Each question should be written in its own .cpp file. Once you’re done, feel free to share your solutions in the community for feedback and peer review.
Question 1: Allocate and Free a Single Integer Using new
Write a program that uses dynamic memory to store a single integer.
First, use new int to allocate memory for the integer and store the value 42 in it. Then print the value stored in the dynamically allocated memory. After that, properly free the memory using delete, and finally set the pointer to nullptr.
Keep reading this lesson
You've reached the end of the free preview. Unlock the rest of this lesson plus 21 more lessons in Mastering C++.
- Unlimited coding questions
- Unlimited access to all classroom material
- Weekly live call for questions and guidance
- 3,000 AI tutor tokens / month
- Personal SQL database (3 MB)
- Progress tracking
Cancel any time.