Q:

pop() is not working properly

Here is a c++ code on stack.Ignore the extra code here
#include<iostream>
using namespace std;
class mystack
{
    private:
        int top;
        int size;
        int * s;
    public:
        void initialize()
        {
            top=-1;
            cin>>size;
            s=new int[size];
        }   
        ~mystack(){delete [] s;}
        void push()
        {
            int x;
            if(top==size-1)
                cout<<"stack overflow!"<<endl;
            else
            {
                cout<<"Enter element to be pushed:";
                cin>>x;
                top++;
                s[top]=x;
                cout<<s[top]<<endl;
            }
        }   
        int pop()
        {
            int p=s[top];
            if(top==-1)
                return 0;
            else
            {
                top--;
                return p;
            }
        }
        int maxsize()
        {
            return size;
        }
        int isempty()
        {
            if(top==-1)
                return 0;
            else
                return 1;
        }
        void display()
        {
            int i,p=top;
            cout<<s[0]<<endl;
            for(i=0;i<=p;i++)
                cout<<s[i]<<endl;
        }
};
int main()
{
    int n,i;
    cout<<"Enter no. of stacks:";
    cin>>n;
    mystack * st=new mystack[n];
    for(i=0;i<n;i++)
    {
        cout<<"Enter size of stack "<<i+1<<":";
        st[i].initialize();
    }
    int c,s;
    while(1)
    {
        cout<<"*****Operations*****"<<endl;
        cout<<"1.Push 2.Pop 3.Maxsize 4.isempty 5.Display 6.Quit"<<endl;
        cout<<"Enter your choice:";
        cin>>c;
        if(n>1)
        {
            cout<<"Operation on which stack:";
            cin>>s;
        }
        else
            s=1;
        if(c==1)
            st[s-1].push();
        else if(c==2)
        {
            if(st[s-1].pop()==0)
                cout<<"stack underflow!"<<endl;
            else
                cout<<st[s-1].pop()<<endl;
        }
        else if(c==3)
            cout<<st[s-1].maxsize()<<endl;
        else if(c==4)
        {
            if(st[s-1].isempty()==0)
                cout<<"True"<<endl;
            else
                cout<<"False"<<endl;
        }
        else if(c==5)
            st[s-1].display();
        else if(c==6)
            break;
        else
        {
            cout<<"Wrong input!"<<endl;
            continue;
        }
    }   
    return 0;
}

Here accessing pop operation gives the element of top-1.I can't understand why.What should I do?When I do return s[top--] same thing is happening.

A:

Since you haven't gotten back to this, I am going to presume you've already found your logic error.
So here is the one error I found.  There may be more, I quit looking ... 
In the following code, how many times is pop() being called?
  else if(c==2)
    {
        if(st[s-1].pop()==0)
            cout<<"stack underflow!"<<endl;
        else
            cout<<st[s-1].pop()<<endl;
    }

