constk

TransferArraysToFunctions

Dec 10th, 2019
137
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #define _CRT_SECURE_NO_WARNINGS
  2. #include <stdio.h>
  3. #include <iostream>
  4.  
  5. const int n = 10;
  6.  
  7. void max(int[]);
  8. void null(int*);
  9. void show(const int*);
  10.  
  11. int main() {
  12. setlocale(0, "Russian");
  13.  
  14. int array[n] = { 0,1,2,3,4,5,6,7,8,9 };
  15.  
  16. show(array);
  17. max(array);
  18. show(array);
  19. null(array);
  20. show(array);
  21.  
  22. system("pause");
  23. return 0;
  24. }
  25.  
  26. void max(int a[]) {
  27. static int counter1 = 0;
  28. counter1++;
  29. printf("#function max is called %d time\n", counter1);
  30. int max = a[0];
  31. for (int i = 0; i < n; i++)
  32. if (a[i] > max) max = a[i];
  33. for (int i = 0; i < n; i++)
  34. a[i] = max;
  35. }
  36. void null(int *a) {
  37. static int counter2 = 0;
  38. counter2++;
  39. printf("#function null is called %d time\n", counter2);
  40. for (int i = 0; i < n; i++) {
  41. *a = 0;
  42. a++;
  43. }
  44. }
  45. void show(const int *a) {
  46. printf("array is{");
  47. for (int i = 0; i < n; i++) {
  48. printf(" %d,", *a);
  49. a++;
  50. }
  51. printf("}\n");
  52. }
RAW Paste Data