我想在函數中傳遞結構成員。我的意思不是這樣的事情:在函數中傳遞結構成員
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;
其成員通過與變量溫控功能而不是struct變量
int pop(int head,int n)
{
if(head==n)
return 1;
else head++;
}
因爲我不t只想使用該功能的結構。可能嗎?
編輯我希望數字也改變,而不是像指針一樣返回。
EDIT_2另外我知道這個彈出(exp1.head,n)它的工作原理,但我也希望exp1.head在函數彈出結束後更改。
你可以傳遞結構變量的地址並使用它。你需要一些其他的方式比指針? – LearningC
我想盡一切辦法,但我想要的結構,我發送功能的成員的數量也改變這就是爲什麼我提到指針 – valkon