Search code examples
c++data-structuresstack

In the following code, does pop() actually removes the item from the array 'num' or the item still exists inside the 'num'?


Does pop function really removes the item from the array, it just changes the pointing index?

int STACK::pop()
    {
        int temp;
        if(isEmpty())
            return -9999;
        temp=num[top];
        --top;
        return temp;
     }

Solution

  • No, the element isn't removed from the array. It isn't possible to add or remove elements of an array. Arrays have constant number of elements through their lifetime.