is not the first time I've asked this question...but i hope this time i get a very clear answer once and for all...the difference between constant pointers and general pointers...
i've been told several times that constant pointers dont change??? meaning they point to one thing? but well in this code chkItem is a constant pointer but by moving in the for loop it is changing...so can someone please clarify once and for all? I just taken the habit of using constant pointers all the time i code...but well..is time i really understood this thing..thanks in advance
- Here, the data pointed at by pInt can't be changed once it is set, but you can change the location pInt it pointing at.
int* const pInt;
- Here, the memory-location of pInt can't be changed meaning, pInt++ is illegal, meaning you can't make pInt point to another memory location, but you can change the value holded by the location pointed at by pInt once it's set.
I don't know if this is exactly what you meant, but hope it helps.
What is the type of arr? If it was defined as constint arr[50];, then the expressions arr[0] and arr[49] are both expressions of type const int. The expressions arr, arr+0, arr+49 are of type const int * or in other words pointer to const int.
Jacobhaha...you are the first person explaining it like this..thanks a lot...you hit the nail right on the head without beating about the bush..THANKS A LOT! this will solve a lot of problems..thanks again!!! and thanks pheininger...jacobhaha's explanation made me get everything!!!
this is a pointer to const int ,the pointer to int wont allow you to change the item it points to
Through the pointer But can allow you to change from one const int to another
A const pointer would look like like this [code ]int *const chkitem [/code] for this you can Change the value of the variable it points to but you can't make it point to another variable