S
songfire
Hi everybody!
Just wondering if it is possible to point to variables in the heap.
For example, is this okay?
int * ptr_to_DAIA; // pointer to dynamically allocated integer array
ptr_to_DAIA = new int [SIZE];
for(i=0; i<SIZE; i++) ptr_to_DAIA=i;
// now say I want a pointer that points to the element that contains
value TARGET
int * ptr_to_elem_in_DAIA; // pointer to element in DAIA
for(i=0; i<SIZE; i++) if(ptr_to_DAIA=TARGET)
ptr_to_elem_in_DAIA=&ptr_to_DAIA;
In other words, other than the whole bare pointer=bad issue, will this
code be stable? Will ptr_to_elem_in_DAIA always point to the right
place in the heap? Are there any subtle issues I should worry about
here?
Thanx.
Just wondering if it is possible to point to variables in the heap.
For example, is this okay?
int * ptr_to_DAIA; // pointer to dynamically allocated integer array
ptr_to_DAIA = new int [SIZE];
for(i=0; i<SIZE; i++) ptr_to_DAIA=i;
// now say I want a pointer that points to the element that contains
value TARGET
int * ptr_to_elem_in_DAIA; // pointer to element in DAIA
for(i=0; i<SIZE; i++) if(ptr_to_DAIA=TARGET)
ptr_to_elem_in_DAIA=&ptr_to_DAIA;
In other words, other than the whole bare pointer=bad issue, will this
code be stable? Will ptr_to_elem_in_DAIA always point to the right
place in the heap? Are there any subtle issues I should worry about
here?
Thanx.