c - 我不知道为什么指针对于函数的使用不同

标签 c

我不知道指针的概念所以我问。 我不知道为什么指针对于函数的使用不同。

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/

相关文章:

c - RFComm-客户端while循环在服务器被杀死时不会结束

c - 为什么 atoi 和 strtol 大多数时候只返回字符串中的第一个数字?

C 堆地址在运行之间发生变化,而其他地址仍然存在

c - 使用 C 递归删除目录

c - 如何传递参数

C - Makefile 可能缺少一行

c - realloc 函数破坏了应用程序

c - 如何使用函数将字符附加到 C 中的字符串

c - malloc 一次,然后在结构数组上分配内存

c - 如何计算数字序列中的谷数?