The realloc function in C Programming

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

int main()
{
    int *ptr = malloc(sizeof(int));
    if (ptr)
    {
        printf("Allocated bytes : %zu\n", sizeof *ptr);
    }
    int *newPtr = realloc(ptr, 10 * sizeof(int));
    if (newPtr)
    {
        printf("After New Allocation\n");
        printf("Memory Size is : %zu\n", 10 * sizeof(int));
        free(newPtr);
    }
    else
    {
        free(newPtr);
    }
    return 0;
}

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply

Your email address will not be published. Required fields are marked *