Postfix notation stack C++ : <p>I am new to C++ and I want to use a stack to evaluate an expression given as an input (2+3*5+4 for example), containing only numbers, + and *. I wrote this code but it gives me Segmentation fault: 11. Could you please help me solve this or give me a hint about what could be wrong? Thank you! (I noticed there were similar questions on this site, but I couldn't use them to solve my problem)</p>

<pre><code>#include &lt;iostream&gt;
#include &lt;stack&gt;
using namespace std;

bool highPrecedence(char a, char b){
    if((a=='+')&amp;&amp;(b=='*'))
        return true;
    return false;
}

int main()
{
    char c = 'a';
    double x;
    stack&lt;char&gt; stack;
    double v[10];
    int i=0;
    double res;
    while(true)
    {
        c = cin.get();

        if(c=='\n'){
            while(stack.size()!=0){
                if (stack.top()=='*'){
                    double res = v[i]*v[i-1];
                    i--;
                    v[i]=res;
                    stack.pop();
                }
                if (stack.top()=='+'){
                    res = v[i]+v[i-1];
                    i--;
                    v[i]=res;
                    stack.pop();

                }
            }
            break;
        }

        if ( '0'&lt;=c &amp;&amp; c&lt;='9' )
        {
            cin.putback(c);
            cin&gt;&gt;x;
            cout&lt;&lt;"Operand "&lt;&lt;x&lt;&lt;endl;
            i=i+1;
            v[i]=x;
        }
        else
        {
            if(c!=' ') cout&lt;&lt; "Operator " &lt;&lt;c&lt;&lt;endl;
            if (stack.size()==0)
                stack.push(c);
            else{
                while((!highPrecedence(stack.top(),c)) &amp;&amp; (stack.size()!=0)){
                    if (stack.top()=='*'){
                        double res = v[i]*v[i-1];
                        i--;
                        v[i]=res;
                        stack.pop();
                    }
                    if (stack.top()=='+'){
                        res = v[i]+v[i-1];
                        i--;
                        v[i]=res;
                        stack.pop();

                        }
                    }

                stack.push(c);
                }
            }

        }


    cout&lt;&lt;v[0]&lt;&lt;endl;
}
</code></pre>
