Why dont I have to dereference the pointer here? After all, array[i] is _pointing_ to an int, right? I have to dereference the pointer if I do the same thing with an int, so the same should be true for arrays, or so I thought.
Next, what exactly does delete do?
Most tutorial sites claim it _frees_ memory which I assume means it deletes the pointer array. If so, how can I assign array a value of null later? array shouldnt exist right?
And a unrelated question now. What do header files exactly contain?
I've been told they contain prototypes of functions. If this is true where are the actual functions themselves defined?
Sorry if my questions are stupid, but its just that I'm fairly new to C++ and wasnt able to find answers to these questions in a few of the tutorial sites that I learnt from.
The int *array=newint[size]; declares a pointer to an int. Then it creates a new, dynamic, array of integers from this pointer. You don't need to dereference it, you just need to use the delete keyword, somwhere before your end, to free the memory allocated by the pointer.
You can read more about that in the tutorial from this site: http://www.cplusplus.com/doc/tutorial/dynamic.html
Header files contain code that can help you out with your program. It can be some STL function or custom made functions.
It mostly helps you organize your code because you can have in seperate .h files some functions and use them whenever you need them without rewriting them.
Usually people write the function prototypes in a header file and the functions themshelves in the main file. This is a method to avoid using a function that hasn't been declared yet.
In regards to your first question, maybe I can explain.
int * array;
declares a pointer to an integer, which for the most part can be used the same as a one-dimensional array. The new int[size] portion says that this pointer will point to the first integer in a row of integers that has "size" number of integers. Thus array[i] is the same as saying *(array+i).
You are not creating an array of pointers, you're just creating an array of integers. The [size] is just saying how many integers you plan on storing in that memory block (and thus how much it allocates). So the array pointer is basically pointing to the first in a line of integers.
Later on when you delete the array it "frees" (that's the C function) the memory, but the pointer is still around and so you set the pointer value to NULL. Remember, it's a single pointer, not an array of pointers, so this is valid. Otherwise you would have to go through and set each one to NULL (at least, maybe...I can't remember if with pointer arrays you can just set the name equal to NULL.)
edit: wow, it took me that long to write my response...geez
But I still dont get the header files thing. I mean, if I the getline function in the iostream header file only contains the prototype of getline, where is getline actually defined?