Im defining ac function and need to assign a value to members of a structure passed by address into the function, for example i defined the structure called cell:
typedef struct AB
{int A;
char val;
}cell;
i wrote a function called Available where a cell is passed by address into the function. i need to fill the integer member A within the cell with a parameter given by the user, here is my approach.
void available(cell *c,int v)
{ *c.A=v;
}
my question is am i able to do so? like *cA=v?
Normally you would use the arrow operator:
c->A = v;
but you can also do it like this:
(*c).A = v;
Note that you need the parentheses to deal with operator precedence in this case.
Use
(*c).A=v;
or
c->A=v;
instead of
*c.A=v;
The valid assignment will look either like
void available( cell *c, int v )
{
( *c ).A = v;
}
or like
void available( cell *c, int v )
{
c->A = v;
}
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.