I’ve got a structure which holds names and ages.
I’ve made a linked-list of these structures, using this as a pointer:
aNode *rootA;
in my main.
Now i send **rootA to a function like so
addElement(5,"Drew",&rootA);
Because i need to pass rootA by reference so that I can edit it in other functions (in my actual program i have two roots, so return will not work)
The problem is, in my program, i can’t say access the structure members.
*rootA->age = 4;
for example doesnt work.
Hopefully you guys can help me out.
Thanks!
It’s hard to tell from your question but it looks like the type of
rootAin the last sample isaNode**. If so the reason why it’s failing is that->has higher precedence than*. You need to use a paren to correct this problemSee full C Operator Precedence Table.
If the type of
rootAis insteadaNode*. Then you don’t need to dereference in addition to using->. Instead just use->directly