Content pfp
Content
@
0 reply
0 recast
0 reaction

Anton pfp
Anton
@antohin
Do you remember how we filled the array automatically? šŸ”„ šŸ”„ šŸ”„ GOOD! šŸ”„ šŸ”„ šŸ”„ Now, based on this code, we will create a function that will do this. We will call this function filling_the_array. Note how we filled two arrays using this function. At the same time, we described the code for filling only once :) #include <stdio.h> #include <stdlib.h> // Declaration int* filling_the_array(int* array); int main() { int* ptr_1 = NULL; // Firt function using ptr_1 = filling_the_array(ptr_1); for(int i = 0; i<5; i++) printf("%d ", *(ptr_1+i)); printf("\n"); int* ptr_2 = NULL; // Second function using ptr_2 = filling_the_array(ptr_2); for(int i = 0; i<5; i++) printf("%d ", *(ptr_2+i)); return 0; } // Description int* filling_the_array(int* array) { int* next_ptr = NULL; array = (int*)malloc(5*sizeof(int)); for(next_ptr = array; next_ptr-array<5; next_ptr++) *next_ptr = rand()%9; return array; }
0 reply
0 recast
0 reaction