我不知道指针的概念所以我问。 我不知道为什么指针对于函数的使用不同。
int is_full(StackType *s)
{
return (s->top == (MAX_STACK_SIZE -1));
}
void push(StackType *s, element item)
{
if (is_full(s)) {
fprintf(stderr, "error\n");
return;
}
else {
s->data[++(s->top)] = item;
}
}
int main()
{
StackType s;
init_stack(&s);
push(&s, 1);
push(&s, 2);
push(&s, 3);
printf("%d\n", pop(&s));
printf("%d\n", pop(&s));
printf("%d\n", pop(&s));
}
在第一个函数中,我设置 is_full(StackType *s)
在第二个函数中,我设置 push(StackType*s, element item)
第二个函数调用if (is_full(s))
主要来电push(&s, 1)
同样的函数,为什么调用方式不同?
最佳答案
函数main
中变量s
的类型为StackType
。
函数is_full
中变量s
的类型为StackType*
。
关于c - 我不知道为什么指针对于函数的使用不同,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55689276/