Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<string.h>
- #include<stdlib.h>
- #include<math.h>
- int x = 3; //global variable
- int getNextRandomValue(void);
- void populate_array(int *array, size_t arraySize, int (*getNextValue)(void));
- int main()
- {
- int c = 1;
- float a=3.1, b=3.5;
- int myarray[10];
- // populate_array(myarray, 10, getNextRandomValue); //option
- populate_array(myarray, 10, &getNextRandomValue);
- printf(" myarray[2] is %d \n", myarray[2]);
- return 0;
- }
- int getNextRandomValue(void){
- return rand()%100;
- }
- //option
- //void populate_array(int *array, size_t arraySize, int (*getNextValue)(void)){
- void populate_array(int *array, size_t arraySize, int getNextValue(void)){
- for (size_t i=0; i<arraySize; i++)
- array[i] = getNextValue();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement