{}
CODE VISUALIZER
Learn DSA the way it should be — with step-by-step code visualization.
Try now!
CODE VISUALIZER
Learn DSA with step-by-step code visualization.
Try now!
run-icon
main.c
#include <stdio.h> #include <stdlib.h> int main() { int *arr, n, i; // Ask how many integers to store and use calloc() printf("Enter the number of integers to store: "); scanf("%d", &n); arr = (int *)calloc(n, sizeof(int)); // Using calloc instead of malloc if (arr == NULL) { printf("Memory allocation failed!\n"); return 1; } // Display values after calloc (initialized to zero) printf("After calloc, the integers are (initialized to zero): \n"); for (i = 0; i < n; i++) { printf("%d ", arr[i]); } printf("\n"); // Free the memory at the end free(arr); return 0; }
Output