#include <stdio.h>
#define MAX_SIZE 5
// Function to insert value at the end of the array
void insertAtEnd(int arr[], int *size, int value) {
if (*size >= MAX_SIZE) {
printf("Array is full, cannot insert %d\n", value);
return;
}
arr[*size] = value; // place value at current end
(*size)++; // move end forward
}
// Function to print the array
void printArray(int arr[], int size) {
for (int i = 0; i < size; i++) {
printf("%d", arr[i]);
if (i < size - 1) printf(" -> ");
}
printf(" -> null\n");
}
int main() {
int arr[MAX_SIZE] = {1, 2, 3};
int size = 3; // current number of elements
insertAtEnd(arr, &size, 4);
printArray(arr, size);
return 0;
}check if array is full to avoid overflow
arr[*size] = value; // place value at current end
insert new value at the current end index
(*size)++; // move end forward
increment size to update end position