C - Use of free() function using calloc() Code Example

The code for Use of free() function using calloc()

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

int main() {
  int* ptr;
  int n = 25;

  // Dynamically allocate memory using calloc()
  ptr = (int*)calloc(n, sizeof(int));

  // Chceck whether memory is allocated or not
  if (ptr == NULL) {
    printf("Memory not allocated \n");
  printf("Memory allocation is done.\n");

  // Freeing the memory using free() function

  printf("Memory freed.");

  return 0;

Memory allocation is done.
Memory freed.
Code by IncludeHelp, on August 11, 2022 19:57

Comments and Discussions!

Load comments ↻

Copyright © 2024 www.includehelp.com. All rights reserved.