关于指针乱指。。。求分析
#include<iostream>using namespace std;
#define STACK_INIT_SIZE 100
#define STACKINCREMENT 10
typedef struct
{
int *base;
int *top;
int stacksize;
}SqStack;
/*初始化一个栈*/
void InitStack(SqStack *S)
{
S->base=(int *)malloc(STACK_INIT_SIZE*sizeof(int));
if(!S->base) exit(0);
S->top=S->base;
S->stacksize=STACK_INIT_SIZE;
}
/*压栈操作,把元素e压入栈中*/
void Push(SqStack *S,int e)
{
if(S->top-S->base>=S->stacksize)
{
S->base=(int *)realloc(S->base,(S->stacksize+STACKINCREMENT)*sizeof(int));
if(!S->base) exit(0);
S->top=S->base+S->stacksize;
S->stacksize=S->stacksize+STACKINCREMENT;
}
*(S->top++)=e;
}
/*出栈操作,把栈顶元素弹出栈*/
int Pop(SqStack *S,int e)
{
if(S->base==S->top)
exit(0);
e=*(--S->top);
return e;
}
/*取得栈中元素的个数*/
int GetNumber(SqStack S)
{
return (S.top)-(S.base);
}
void main()
{
int bitNumber,tenNumber=0,n,count=0,s=0;
int i,j;
cout<<"二进制:"<<endl;
SqStack stack;//?????
InitStack(&stack);//????
}
最后带?????的地方 若是改成Sqstack *stack;InitStack(stack);会产生指针乱指错误。。。。为什么????