I am learning C++ and I know the 'new' key word is used to allocate an address in memory to a pointer. And I think when using 'nullptr' initializes a pointer which points to nothing. Is that correct? Example for reference:
//using nullptr
int *x = nullptr; //this is just a pointer that points to nothing and
//will need to be initialized with an address before it
//it can be used. Correct?
//using new
int *x = new int; //this is basically giving x an address in memory. Will the
//address have some residual value stored in it or will
//it contain zero?
When would you use one over the other? Is new only used for dynamic memory allocation or are there other applications for it? Why would you initialize a pointer to nullptr if you could just declare it and then initialize it later?
Thanks for the help!