Local variables live on the stack and disappear when the function returns, so a function cannot return a pointer to its local array. Memory from malloc lives on the heap until you call free on it. malloc(n * sizeof(int)) asks for room for n integers; sizeof gives the size of a type in bytes, so the code stays right on any platform.
malloc returns NULL when it cannot allocate, so check before using the result. Every block you allocate must be freed exactly once: forgetting is a leak, freeing twice or using a block after free is undefined behavior. A function that returns heap memory says so in its documentation, and the caller becomes responsible for freeing it.
A string copy needs strlen(s) + 1 bytes: the extra byte holds the terminating zero.