Friday, July 9, 2010

Recycling pointers

Today on my OOP344(c++) subject I learned that when we delete a pointer,

int main(){
int* b;
b=new int[3];
b[0]=3;
delete b;
b[0]=7;
printf("%d\n",*b); //7 will be printed here
return 0;
}

we actually deleting not the pointer (ptr) but what stored in the address.
And we don't need to declare the pointer again if we want to reuse it.
We can assign the pointer a new value without declaring it again.

That is what I call true recycling but not that useless curbside recycling program

No comments:

Post a Comment