C语言动态内存分配

 

 

#include <iostream>
#include<stdio.h>




int* removeDuplicates(int numsSize) {

    // malloc是常用的动态内存分配

    int* arr = (int*)malloc(numsSize * sizeof(int));

    return arr;
}


int main() {

    int numsSize = 10;

    int* arr;

    arr = removeDuplicates(numsSize);

    for (int i = 0; i < numsSize; i++) {
        arr[i] = i+2;
    }


    for (int i = 0; i < numsSize; i++) {
        printf("%d\n", arr[i]);
    }


    return 0;
}

 

posted @ 2023-09-25 09:36  朵朵奇fa  阅读(7)  评论(0编辑  收藏  举报