Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
383 views
in Technique[技术] by (71.8m points)

struct - How to work with pointer to pointer to structure in C?

I want to change member of structure under double pointer. Do you know how?

Example code

typedef struct {
    int member;
} Ttype;

void changeMember(Ttype **foo) {
   //I don`t know how to do it
   //maybe
   *foo->member = 1;
}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Try

(*foo)->member = 1;

You need to explicitly use the * first. Otherwise it's an attempt to dereference member.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...