I was looking at this tutorial about the stack and heap:
When to use new operator in C++ and when it should not be used?
And in the heap example, it uses the new
keyword, but he began by initializing int* ptr1
to NULL
. Is that important, and if so why? Or, is it just wasting space?
I looked at the code and tried thinking why use NULL
first when you could just use int* ptr1 = new int(28);
?
Side note: If someone could also explain the stack and heap in laymans terms, it would be appreciated.