Stack Push

Sure! Here is an example of how to implement the push operation for a stack in the C programming language:

#include <stdio.h>
#define MAX_SIZE 100

int stack[MAX_SIZE];
int top = -1;

void push(int item) {
   if (top >= MAX_SIZE - 1) {
      printf("Stack Overflow\n");
   } else {
      top++;
      stack[top] = item;
   }
}

int main() {
   push(10);
   push(20);
   push(30);
   push(40);

   printf("Elements in stack are: ");
   for (int i = 0; i <= top; i++) {
      printf("%d ", stack[i]);
   }

   return 0;
}

In this example, we define a stack with a maximum size of 100 using an array stack. The variable top keeps track of the index of the top element in the stack, initialized to -1 to indicate an empty stack.

The push function takes an item as a parameter and checks if the stack is already full by comparing top with MAX_SIZE - 1. If the stack is full, it prints "Stack Overflow". Otherwise, it increments top and adds the item to the stack array at the updated top index.

In the main function, we demonstrate the push operation by calling it four times with different items. Finally, we print the elements in the stack by iterating over the stack array from index 0 to top and printing each element.

This example illustrates how to implement the push operation for a stack in C without using any personal words or sentences.