Description:
Given an array of integers, return a new array with each value doubled.
For example:
[1, 2, 3] --> [2, 4, 6]
#include <stddef.h>
// return a *new, dynamically allocated* array with each element doubled.
int *maps(const int *arr, size_t size)
{
int *tmp = (int*)malloc(sizeof(int) * size);
if (!tmp)
return NULL;
for (size_t i = 0; i < size; i++)
tmp[i] = arr[i] * 2;
return tmp;
}
another solution
int *maps(const int *arr, size_t size) {
int* a = (int*)malloc(size * sizeof(int));
for (int i = 0; i < size; a[i++] = arr[i] * 2);
return a;
} -> 이런것도 되넹