#include <stdio.h>
void insertAtBeginning(int arr[], int *size, int capacity, int value) {
if (*size >= capacity) {
printf("Array is full, cannot insert\n");
return;
}
// Shift elements right to make space at index 0
for (int i = *size - 1; i >= 0; i--) {
arr[i + 1] = arr[i]; // move element one step right
}
arr[0] = value; // insert new value at beginning
(*size)++; // increase size
}
void printArray(int arr[], int size) {
for (int i = 0; i < size; i++) {
printf("%d", arr[i]);
if (i != size - 1) printf(" -> ");
}
printf("\n");
}
int main() {
int capacity = 10;
int arr[10] = {1, 2, 3, 4, 5};
int size = 5;
insertAtBeginning(arr, &size, capacity, 0);
printArray(arr, size);
return 0;
}for (int i = *size - 1; i >= 0; i--) { arr[i + 1] = arr[i]; }
Shift all elements one position right to free index 0
Insert new value at the beginning of the array
Increase the size of the array after insertion
0 -> 1 -> 2 -> 3 -> 4 -> 5