I am trying to allocate memory for an integer array
ptr=malloc(length*sizeof(int));
which will give me the pointer to the allocated memory. I understand that I can access the values with *(ptr+k), where k is the position in the integer array. However is there a way to define a new array
int allocarray[length];
and then assign allocarray the address ptr, so that I can access the stored values with
allocarray[k]
? I tried the following which does not work:
allocarray=ptr;
Thank you for the help.