【发布时间】:2014-03-26 18:11:53
【问题描述】:
我想在 function 中传递 struct 成员。我不是那个意思:
struct smth
{
int n;
};
void funct(struct smth s);
我想要这些结构
struct student {
char name[50];
int semester;
};
struct prof {
char name[50];
char course[50];
};
struct student_or_prof {
int flag;
int size;
int head;
union {
struct student student;
struct prof prof;
}
}exp1;
struct student_or_prof *stack;
struct student_or_prof exp2;
用变量而不是结构变量在函数中传递它们的成员
int pop(int head,int n)
{
if(head==n)
return 1;
else head++;
}
因为我不想只将函数用于结构。有可能吗?
编辑我希望数字也改变,而不是返回,类似于指针。
EDIT_2我也知道这个 pop(exp1.head,n) 可以工作,但我也希望 exp1.head 在函数 pop 结束后改变。
【问题讨论】:
-
你可以传递struct变量的地址并使用它。除了指针,你还需要其他方法吗?
-
我想要所有可能的方式,但我也想要我发送给函数的结构成员的数量也改变这就是我提到指针的原因