Generate Lists of Numbers in an Interactive Manner and use function calloc() for dynamic allocation of memory - C Memory

C examples for Memory:calloc

Description

Generate Lists of Numbers in an Interactive Manner and use function calloc() for dynamic allocation of memory

Demo Code

#include <stdio.h>
#include <stdlib.h>

int main()/*from   w  ww  .ja  va 2s .  c  o  m*/
{
   int n, i, j;
   int *ptr, *list[10];
   printf("Enter an integer as size of list (1 <= n <= 20): ");
   scanf("%d", &n);
   for (i = 0; i < 10; i++) {
      list[i] = (int *)calloc(n, sizeof(int));
      for (j = 0; j < n; j++)
         *(list[i] + j) = i + j + 10;
   }

   printf("Displaying the values of items in list\n");
   for (i = 0; i < 10; i++) {
      printf("List[%d]: ", i);
      for (j = 0; j < n; j++) {
         printf("%d ", *(list[i] + j));
      }
      printf("\n");
   }

   return(0);
}

Result


Related Tutorials