I have a function which creates a dynamic array the size of my selected integer. Code:
int *create(int n) {
int *nn;
nn = (int*)malloc(n*sizeof(int));
return nn;
}
And I call it like this in my main()
int *nn
int n = 5; /* size = 5 */
nn = create(n);
I think I get the part, int *create(...) which is supposed to return the address to the first position of my returned nn. However I wonder, is there a way to not use the pointer in a function and instead modify the return nn; part so that I still return the address of the dynamic array nn?
I want to remove the * in the *create
return (int*) malloc(n*sizeof(int)) ?int * nn = malloc(n*sizeof(int));You don't cast malloc in c. So the example is a little confusing.*? It's possible but it ain't pretty.*from thecreatefunction declaration/definition? What is your justification? Do you mean that you don't want the function to return a pointer value? If not, why not?