Good day. There was the following problem. The following code is available:
int leng[10] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; int *res; res = (int*)malloc(8*sizeof(int)); // на 8 не обращайте внимание memset(res, 0 , 8); res = func(leng, 10, 8); // ... Here is the code of the func function itself:
static int* func(int *arr, int len, int size) { int *arrTemp; int i = 0; arrTemp = (int*)malloc(len* sizeof(int)); memset(arrTemp , 0, len); for (i = 0; i < length; i++) printf("%d ", *(arrtemp + i)); // ... } On the screen when printing the first three elements as in the original array, the rest is garbage. Help me figure out why?