Pointers and NULL
Ive' been wondering about pointers i know they are quite important in C++ but what exactly do they do? I would also like to know what NULL means. I think it means something like no value or 0, but im not sure, please tell me. Any help would be great. :)
NULL doesn't really mean anything else but a pointer with value of zero. This generally indicates that the pointer isn't pointing to anywhere.
A pointer is an address to an object in memory. So if I have a pointer to int called pInt. The value inside pInt is that specific location where the variable int is in memory.
Same thing if you have an array of int's. Usually the pointer points to the first element in array, and all the other elements can be pointer via the pointer.
int a = 10;
int* pInt = &a; // declare a pointer to int type data and set a's address to it
int* pArray = &array; // 1
int* pArray = array; // 2
// cases 1 and 2 are exactly the same thing
cout << *pArray; // print out the first element in array
cout << *(pArray+1); // print out the second element in array