stack에 대해서 질문좀드릴께요 ㅜㅜ

질문 제목 : 질문 내용 :
#include stdio.h
#include stdlib.h
#include time.h

int stack[30];
int stac[30];
int x=0,y=0;
int top=0;
int i,j;

void push(int x,int y)
{
stack[++top]=x;
stac[++top]=y;
}
int pop()
{
x=stack[top--];
y=stac[top--]; return 0;
} int main(void)
{
scanf(%d %d,&x,&y);
push(x,y);

pop();
printf(%d %d\n,x,y);
printf(%d %d,stack[top],stac[top]);
return 0;

}

여기서 왜 결과값이 입력값이아니고 0 0 만나오는걸까요?

댓글 2

  • 츠키코 2026.06.18

    ㅜㅜ 그렇게바꿔도안되는데요 . .

  • 유키 2026.06.18

    우선 pop 함수는 돌려주는 값이 없으므로
    void pop(void)
    {
    x = stack[top--];
    y = stack[top--];
    }
    이렇게 구성해야 됩니다.

C언어 다른 글

목록