With this struct
typedef struct tNode_t {
struct tNode_t **a;
} tNode;
I want to be able to have a
point to an array to 5 pointers to tNodes
example main:
int main()
{
tNode t;
tNode (*alpha)[5];
t.a = alpha;
}
why doesn't this work?
This defines a pointer to an array of tNodes:
tNode (*alpha)[5];
This defines an array of pointers to tNodes:
tNode *alpha[5];
In your code alpha
and a
are pointers to very different objects. And since both are pointers, as you correctly defined them, no decaying will take place . Only arrays decay so alpha
can't simply decay to another pointer type.
And why are they so different ? When you increment a, it will point to the next struct tNode_t *
. When you increment alpha
it will point 5 struct tNode *
further.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.