title: How to push elements in a stack using C
body: <p>I tried to learn a stack in C. But unable to do the push operation as it shows some errors in it. There is no error message shown in the console. But when running the code, it shows a wrong top value when executing the peek method.</p>
  
  <pre><code>#include&lt;stdio.h&gt;
  #include&lt;stdlib.h&gt;
  #define MAX 50
  typedef enum{FALSE,TRUE} boolean;
  typedef struct stack{
      int top;
      int a[MAX];
   }stack;
  void CreateStack(stack s){
      s.top = -1;
   }
   boolean isEmpty(stack s){
      return (s.top == -1);
  }
  boolean isFull(stack s){
      return(s.top == MAX - 1);
  }
  void push(stack s, int data){
      if(isFull(s)){
          printf("Stack is Full\n");
          exit(1);
      }
      else{
          s.top = s.top + 1;
          s.a[s.top] = data;
      }
   }
   void pop(stack s){
      if(isEmpty(s)){
          printf("Stack is Empty");
          exit(1);
      }
      else{
          printf("%d\n",s.a[s.top]);
          s.top = s.top - 1;
      }
   }
   int peek(stack s){
      return s.a[s.top];
   }
   void main(){
      stack s;
      CreateStack(s);
      int num;
      push(s,1);
      push(s,2);
      push(s,15);
      printf("Top value = %d\n",peek(s));
   }
  </code></pre>