Stack in CodeBlocks

can somoene explain how this compiles nothing in CodeBlocks. thanks beforehand
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include <iostream>
#include <stdexcept>
#include <string>

using namespace std;
#define STACK_SIZE 1000

int stc[STACK_SIZE];
int stack_pointer = STACK_SIZE - 1;

int pop(){
    if(stack_pointer < STACK_SIZE - 1){
        int p = stc[stack_pointer];
        stack_pointer++;
        return p;
    }
    else{
        cout << endl <<"Error: Stack Overflow"<<endl;
    }
    return -1;
}

void push(int p){
     if(stack_pointer > 0){
        stack_pointer--;
        stc[stack_pointer]=p;
     }
     else{
        cout<<endl<<"error: stack overflow"<<endl;
     }
}

int main(){
    int a,b,c,A,B,C;
    a=1971;
    b=8;
    c=28;
    push(a);
    push(b);
    push(c);

    A = pop();
    B = pop();
    C = pop();
    return 0;
}
What do you mean 'compiles nothing'? Does it generate a compile error (compiles OK with VS2019)? Unless there is a stack error, there is no output from the program when it is run.
no error just nothing it shows execution time and press any key to continue


i added this:
cout<<A<<" "<<B<<" "<<C<<endl;
string z;
getline(cin,z);
before return 0; and it worked
Last edited on
From the code, that is what is expected. What output do you want?

If you want to see the values of A B C then you need to display them with a cout statement.

okay i figured it out, thanks!
Topic archived. No new replies allowed.