小编san*_*ank的帖子

C中函数的返回值

我尝试编写一些代码来检查表达式中的paranthesis是否使用以下函数进行平衡.有人可以帮助我理解为什么下面的函数在平衡表达式的情况下返回1,而在任何地方都没有指定返回1.

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <limits.h>

struct Stack
{
    int top;
    unsigned capacity;
    char* array;
};

struct Stack* createStack (unsigned capacity)
{
    struct Stack* stack = (struct Stack*) malloc (sizeof(struct Stack));
    if(!stack)
        return NULL;

stack->top = -1;
stack->capacity = capacity;
stack->array = (char*) malloc(stack->capacity * sizeof(int));

if (!stack->array)
    return NULL;
return stack;
}

int isEmpty(struct Stack* stack)
{
    return (stack->top == -1);
}
void push(struct Stack* stack, char op)
{
    stack->top++;
    stack->array[stack->top] = op;

}

int pop(struct …
Run Code Online (Sandbox Code Playgroud)

c stack return return-type return-value

2
推荐指数
1
解决办法
138
查看次数

标签 统计

c ×1

return ×1

return-type ×1

return-value ×1

stack ×1