October 30, 2025, 03:42:24 PM

News:

Own IWBasic 2.x ? -----> Get your free upgrade to 3.x now.........


POINTERS (our friends...) :)

Started by pistol350, November 11, 2008, 01:35:41 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

pistol350

November 11, 2008, 01:35:41 AM Last Edit: November 11, 2008, 01:37:34 AM by pistol350
I have a few questions about pointers.
First, is it correct to do this :

Pointer pMypointer[10] 'Just an array of pointer

If so, can i initialize this pointer like this ? :

pMypointer=NULL  ' I think this does not work as I would expect it to.  ???

So would this do the job ?
If so, is it the proper way to do that ?

For temp=0 to 9
pMypointer[temp]=NULL
next temp



Thanks.
Regards,

Peter B.

Rock Ridge Farm (Larry)


If I remember correctly (and that is a bit of a reach)

Pointer mypointer[10] declares an array of 10 pointers - an address in the initialized stack area is assigned to the pointer.

mypointer=Null; sets the address of the array of pointers to null - not very useful.

The following sets the contents of each element of mypointer to Null.

For temp=0 to 9
   pMypointer[temp]=NULL
next temp

pistol350

Hi Larry!

Quotemypointer=Null; sets the address of the array of pointers to null - not very useful.
Not very useful indeed as it only initializes the first pointer of the array.

I asked the question because i noticed that pointers are not always initialized after their creation.
So in case i defined an array of pointers just like the example above,
i thought that i should initialize all of them to prevent unexpected results.

Thanks again.
Regards,

Peter B.

Rock Ridge Farm (Larry)

I think that is correct - when a pointer is created it inherits the trash that just happens to
be at the assigned memory location - that is why you should always initialize pointers.
I initialize all vars just to be safe.
You can get some strange results if you do not.