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; }