fork download
  1. #include <stdio.h>
  2. #define SIZE 5
  3. int stack[SIZE];
  4. int sp;//ポインタ
  5.  
  6. void push(int x){
  7. if(sp>=SIZE){
  8. printf("満タン\n");
  9. }else{
  10. stack[sp]=x;
  11. sp++;
  12. }
  13. }
  14.  
  15. int pop(void){
  16. if(sp<=0){
  17. printf("空\n");
  18. return 0;
  19. }else{
  20. return stack[--sp];
  21. }
  22. }
  23.  
  24. int main(void) {
  25. push(1);
  26. push(2);
  27. push(3);
  28. pop();
  29. for(int i=0;i<sp;i++){
  30. printf("stack[%d]=%d\n",i,stack[i]);
  31. }
  32. return 0;
  33. }
  34.  
Success #stdin #stdout 0.01s 5320KB
stdin
110
stdout
stack[0]=1
stack[1]=2