C语言Mallocing Memory问题,求解决

请问这里应该怎么做?要求是说它需要使用 malloc 和 free。并且要求一旦程序运行起来,要确保正确使用了“free”函数来释放内存,然后将指针设置为等于 NULL。照片第一张是原题,第二张是机翻。求帮我编程一下。蟹蟹。

img

img

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

int *createInteger(int value);
double *createDouble(double value);

int main(int argc, char* argv[]) {

    int *heapInteger = createInteger(3);
    double *heapDouble = createDouble(4.0);

    printf("heapInteger: %d\n", *heapInteger);
    printf("heapDouble: %lf\n", *heapDouble);

    // TODO BELOW
    //  part 3: don't forget to free your memory and set their values
    //          to NULL
    // TODO ABOVE
    return 0;
}

// TODO BELOW
//  part 1: Complete the "createInteger" function that uses
//          malloc to store a new integer on the heap
int *createInteger(int value) {
    return NULL; // You don't want to return null
}
// TODO ABOVE

// TODO BELOW
//  part 2: Complete the "createDouble" function that uses
//          malloc to store a new integer on the heap
double *createDouble(double value) {
    return NULL; // You don't want to return null
}
// TODO ABOVE

参考:

char *Ptr = NULL;

        Ptr = (char *)malloc(100 * sizeof(char));

        if (NULL == Ptr)
    {
        exit (1);
    }

        gets(Ptr);

        // code...

        free(Ptr);

        Ptr = NULL;

#include <stdio.h>
#include <stdlib.h>
int *createInteger(int value);
double *createDouble(double value);
int main(int argc, char* argv[]) {
    int *heapInteger = createInteger(3);
    double *heapDouble = createDouble(4.0);
    printf("heapInteger: %d\n", *heapInteger);
    printf("heapDouble: %lf\n", *heapDouble);
    free(heapInteger);
    heapInteger = NULL;
    free(heapDouble);
    heapDouble = NULL;
    return 0;
}
int *createInteger(int value) {
    int *p = (int*)malloc(sizeof(int));
    *p = value;
    return p;
}
double *createDouble(double value) {
    double *p = (double*)malloc(sizeof(double));
    *p = value;
    return p;
}