So, coming from C# I'm trying to learn C++. I've been reading 'Jumping Into C++' and have gone through the three chapters covering Pointers, References, Arrays, and memory allocation. I am now hopelessly confused (I think), even after reading them three times.
I get the basic idea that a pointer is a memory address to another variable.
I also get the idea that a reference is a way to provide a variable with an 'alias' name, though I don't see at the moment what that's supposed to get me.
Arrays? No problem, they're a sequential block of memory addresses.
However, when it comes to memory allocation (Ch. 14 in the book), I'm not following. The book says that to allocate a block of memory for a pointer one needs to use the NEW keyword (e.g. int *ptr = new int). Ok, but doesn't declaring the pointer (e.g. int *ptr) do the same thing by default? It seems to me that unless one sets a pointer to NULL, it has something in it when it is declared, which means it has to have allocated memory.
If that is true, then what is the reason for explicitly allocating memory with the NEW keyword?
Wouldn't that effectively double the memory being 'consumed' by the pointer?
I'm also not following why arrays appear to be treated differently with respect to pointers and memory allocation than any other variable type. It seems to me it's just a variable with a larger block of assigned memory. Why treat it differently?
Clearly, I'm missing something...