C语言Malloc and Strcpy,九九海子吧

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

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


#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);//
    free(heapDouble);//
    heapInteger=NULL;
    heapDouble=NULL;
    return 0;
}

int *createInteger(int value) {
    int *r=(int*)malloc(sizeof(int));
    *r=value;
    return r; 
}

double *createDouble(double value) {
    double *r=(double*)malloc(sizeof(double));
    *r=value;
    return r; 
}
 
// TODO BELOW
//  part 1: Complete the "createInteger" function that uses
//          malloc to store a new integer on the heap
int * createInteger(int value) {
    int *heap=(int *)malloc(sizeof(int)*1);
    *heap=value;
    return heap; // 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) {
    double *heap=(double *)malloc(sizeof(double)*1);
    *heap=value;
    return heap; // You don't want to return null
}
// TODO ABOVE
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
    free(heapInteger);
    heapInteger=NULL;
    free(heapDouble);
    heapDouble=NULL;
    // TODO ABOVE
    return 0;
}