stack erase code example

Example 1: stack c++

stack<int> stk;
stk.push(5);
int ans = stk.top(5); // ans =5
stk.pop();//removes 5

Example 2: stack erase

#include <stdio.h>
#include <stdlib.h>
#include <conio.h>

main() {
  struct node {
     int data;
     struct node *next;
  }*pNew,*dltPtr;

  struct stack_ptr {
     int count;
     struct node *top;
  }*stack;
 int i;
 scanf("%d",&i);
 pNew = new node;
 pNew->data = i;
 pNew->next = NULL;
 stack = new stack_ptr;
 stack->count = 1;
 stack->top = pNew;
 scanf("%d",&i);
 while (i != 0){
     pNew = new node;
     pNew->data = i;
     pNew->next = stack->top;
     stack->count++;
     stack->top = pNew;
     scanf("%d",&i);
 } 
 dltPtr = stack->top;
 while (dltPtr != NULL) {
	  printf("% d",dltPtr->data);
	  dltPtr = dltPtr->next;
     } 
 }