From 8ee901894648a5dd6b9acf74709840420676f368 Mon Sep 17 00:00:00 2001 From: Dhruva Kumar Date: Sun, 28 Jun 2026 21:52:52 +0530 Subject: [PATCH] Improve memory allocation handling and clean up code style --- sorting/bubble_sort.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/sorting/bubble_sort.c b/sorting/bubble_sort.c index 8bd4edf296..e53ec35fba 100644 --- a/sorting/bubble_sort.c +++ b/sorting/bubble_sort.c @@ -70,7 +70,12 @@ void bubbleSort(int *arr, int size) void test() { const int size = 10; - int *arr = (int *)calloc(size, sizeof(int)); + int *arr = calloc(size, sizeof(int)); +if (arr == NULL) +{ + perror("Memory allocation failed"); + exit(EXIT_FAILURE); +} /* generate size random numbers from 0 to 100 */ for (int i = 0; i < size; i++) @@ -86,9 +91,9 @@ void test() } /** Driver Code */ -int main(int argc, const char *argv[]) +int main(void) { - /* Intializes random number generator */ + /* Initializes random number generator */ srand(time(NULL)); test(); return 0;