栈满为什么不会出现异常(C++程序)?
//Push.cpp//This program is to Push SqStack# include <malloc.h># include <iostream.h># include <conio.h># define STACK_INIT_SIZE 10# define STACKINCREMENT 10# define OK 1# define ERROR 0typedef int SElemType;typedef struct SqStack //define structure SqStack{ SElemType *base; SElemType *top; int stacksize;}SqStack;int Push(SqStack &S,SElemType e) //Push() sub-function{ /*if(S.top-S.base>S.stacksize) { S.base=(SElemType *)realloc(S.base,(S.stacksize+ STACKINCREMENT*sizeof(SElemType))); if(!S.base) { cout<<endl<<"Overflow!"; return (ERROR); } S.top=S.base+S.stacksize; S.stacksize+=STACKINCREMENT; }*/ *S.top++=e; return (OK);} //Push() endvoid main() //main() function{ SElemType e; SqStack S; S.stacksize=STACK_INIT_SIZE; S.base=S.top=(SElemType *)malloc(STACK_INIT_SIZE*sizeof(SElemType)); int a = 5; //(S.top)=(&a); //initial the old SqStack *S.top++=5; *S.top++=8; *S.top++=12; *S.top++=18; *S.top++=30; *S.top++=37; SElemType *p; //*p = *(S.top-1);//【local variable 'p' used without having been initialized】 //p = S.top-1; cout<<endl<<endl<<"*S.top=" << *(S.top-1); //cout<<endl<<endl<<"*p=" << *p; cout<<endl<<"========"; cout<< endl << "stack memory:" << S.stacksize; cout<<endl<<endl<<"The old SqStack is (base to top) : "; for(p=S.base;p!=S.top;p++) //output the old SqStack cout<<*p<<" "; while(true){ cout<<endl<<"Please input the data to push into the SqStack : "; cin>>e; if(Push(S,e)) cout<<"Success! S.top = "<<e; //output S.top cout<<endl<<"The new SqStack is : "; for(p=S.base;p!=S.top;p++) //output the new SqStack cout<<*p<<" "; cout<< endl << "element number count:" << S.top-S.base << endl;//S.top-S.base } cout<<endl<<endl<<"...OK!..."; //getch();}