Pointers to more Pointers... 
Author Message
 Pointers to more Pointers...



Quote:
> How do you explicitly store the addresses of pointers within an array
of
> pointers besides dynamic allocation.

> Consider this code:

> node **table,*a,*b,*c,d;
> table=(node **) malloc(2*sizeof(node *));
> a=(node *) malloc(3*sizeof(node));
> b=(node *) malloc(3*sizeof(node));
> table[0]=&a;

You have made table to be an array of two node pointers (type
*node).Therefore you need to assign to the table elements a node pointer
and not the address of a node pointer. Also, you need to test the return
values of malloc. Allocation may fail.

table[0] = a;

Assuming space was allocated, table[0] now is a node pointer to an array
of three type node.

Quote:
> table[1]=&b;

table[1] = b;

Quote:
> c=&d;

> it doesn't seem to work.

In c language, you do not need to cast the return value of function
malloc.

--
Al Bowers

GIBCO Labs.
Tampa FL. USA.

Sent via Deja.com http://www.*-*-*.com/
Before you buy.



Sat, 24 Aug 2002 03:00:00 GMT  
 Pointers to more Pointers...
How do you explicitly store the addresses of pointers within an array of
pointers besides dynamic allocation.

Consider this code:

node **table,*a,*b,*c,d;
table=(node **) malloc(2*sizeof(node *));
a=(node *) malloc(3*sizeof(node));
b=(node *) malloc(3*sizeof(node));
table[0]=&a;
table[1]=&b;
c=&d;

it doesn't seem to work.

Although this works fine:

node **table,*a;
a=(node *) malloc(3*sizeof(node));
table=&a;

Could you explain this to me

-CSK
http://snap.to/csk



Sun, 25 Aug 2002 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Dereferencing f-pointers, arrays of f-pointers, pointers to f-pointers

2. Pointer Functions and Pointers to Pointer Functions

3. Pointers: return of pointer to array of pointers to main

4. Converting from ArrayList pointer to ComboBox pointer

5. Casting function pointer to void pointer

6. int Pointer and struct pointer

7. Assigning structure pointer to function pointer

8. pointer to generic pointer

9. long pointers again -- far pointers

10. How to declare a pointer to the pointer?

11. Pointers assigned to pointers - confused

12. confused null pointer with null pointer constant

 

 
Powered by phpBB® Forum Software