   Pointers Beginner
  Alright I know basically how pointers work, I want yes or no answers, if no explain your answer.(I'm going to use this for all my Pointer questions, I don't want it getting to crowded :) )1. So adding a anterisk to a pointer thats been appointed a address is called deferencing, like the vector iterator? yesQuote:nobodynewsIf you mean you have this code:int * var = &another_var; // 1*var = 10; // 2Then (2) is called dereferencing, like an iterator.
Quote:Original post by scheols1. So adding a anterisk to a pointer thats been appointed a address is called deferencing, like the vector iterator?If you mean you have this code:int * var = &another_var; // 1*var = 10; // 2Then (2) is called dereferencing, like an iterator.   ;  Ah snap nice, I'm understanding ;), question 2 coming very shortly after done with chicken hehe :D   ;  2. A constant pointer can't change the address its pointing to, but a pointer constant can't change the value of the address which the pointer is pointing to?Can the pointer constant change the address which it's pointing to?   ;Quote:Original post by scheols2. A constant pointer can't change the address its pointing to, but a pointer constant can't change the value of the address which the pointer is pointing to?Can the pointer constant change the address which it's pointing to?Consider this example and the errors it generates (in Visual C++ 2005):int main(void){    char name[] = "Some text";    const char * name1 = name;    char * const name2 = name;    name1 = "A";    name2 = "B"; // error C3892: 'name2' : you cannot assign to a variable that is const    name1[0] = '0';    name2[0] = '1'; // error C3892: 'name1' : you cannot assign to a variable that is const}This shows that you can't change where name2 points to.  It also shows you can't change what name1 points to.  There is also a constant pointer to constant data:const char * const name3;You can't change where it points or what it points to.   ;  So basically, the`re both the same except one can change the value and one can't?  Confused a little.   ;Const correctness.Remember, we read pointer declarations, right to left.So a const pointer can't be changed. Makes sense right? What is "changed"? In this context means the pointer cannot be pointed somewhere else. I can change whatever is being pointed to, but I can't point somewhere else. Example. I write down the address of a house in permanent ink. You can go to the house, and do whatever you want. Tear it down. Remodel, whatever. But the written address cannot be changed. You only get to modify that house.A pointer to a const. You can point wherever you like. You just cannot do anything about what you point to. Example. I write down the address of a house in pencil, but forbid you to do anything to the house. You don't like the house, I can give you another address. But you still can't do anything about the other house.   ;Quote:Original post by scheolsSo basically, the`re both the same except one can change the value and one can't?  Confused a little.There are two things going on with my example.  The first is that once name1 points to a memory location it will always point to that memory location.  The data at that memory location CAN change.  So if it was pointing to memory location 0x98765432 it will always point to that memory location.  However, if that memory location holds the value 10, you can change it to 30 or whatever.The second variable, name2, can point to different memory locations.  It can point to memory location 0x54a23f42, or 0x12345678 or whatever. But the data at that memory location can't be changed. If it points to a memory location that holds 10, you can't change it with that pointer.  Something else could change it though, maybe a non const pointer to that memory location.   ;  Aight this is what I found out: (own def)Constant Pointer - Once you point to an address you can't change that address, but you can change the value of that address of what your pointing to.  E.g..:You got a SSN (Social Security number), you can't change that SSN, but you can change your name, your hair and what ever you look like (lol plastic surgery) but you can't change that SSNPointer Constant - You can pointer to any address, you can change the address which you point to, but what ever you point to, you can't change the value of it.Like your tv provider, you can change that channel with the remote control, but you can't change whats on your tv station with the remote control.   ;  Returning Pointers from a function.Alright I'm reading Beginning C++ Through Game Programming, 2nd Edition, it has this part in the pointers chapter about passing pointers to an function and returning them.  The thing I don't get is, how do they tell the function that there is going to be a pointer being passed to the function when the vector isn't a pointer in the get go.  You would have to turn the vector into the pointer first wouldn't you? (came up with this) E.g..:#include <vector>#include <iostream>using namespace std;int main( void ) {   vector<int> numbers;   numbers.push_back(1);   numbers.push_back(2);   numbers.push_back(5);   cout << (*(&numbers))[0];   return 0;}returns 1But in the book its got basically the same thing(but its using string, im using numbers) but the function looks like so:int* ptrToElement(vector<int>* const pV, int i) {return &((*pV));}Yet the shits being passed like:int newPointer = ptrToElement(&numbers,0);How does that even work when the vector isn't even a pointer?