thevals

lab7

Dec 9th, 2021 (edited)
499
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.60 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. void f1(int**, int);
  4. int f2(void(*)(int**, int), int**, int);
  5. int* pptr;
  6. int main() {
  7.     int dim2 = 10;
  8.     void(*pf1)(int**, int);
  9.     pf1 = f1;
  10.     int(*pf2)(void(*ppf1)(int**, int), int**, int);
  11.     pf2 = f2;
  12.     printf("%d\n", pf2(pf1, &pptr, dim2));
  13.     for (int i = 0; i < dim2; i++) {
  14.         printf("%d ", pptr[i]);
  15.     }
  16.     free(pptr);
  17.     return 0;
  18. }
  19.  
  20. void f1(int** m, int dim) {
  21.     *(m) = (int*)malloc(dim * sizeof(int));
  22. }
  23. int f2(void(*fptr1)(int**, int), int** ptr, int dim) {
  24.     fptr1(ptr, dim);
  25.     for (int i = 0; i < 10; i++) {
  26.         (*ptr)[i] = i * i + 1;
  27.     }
  28.     return pptr[8];
  29. }
Add Comment
Please, Sign In to add comment