Arrays in Function

I want to call the array from one function to another all function not a main function
Last edited on
is this your problem? If no, modify for your use!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include <iostream>

using namespace std;

int beta(int* b, int dim){
   //find arrayMax of called array
   int max = b[0];
   for(int i = 1; i < dim; ++i)
      if(b[i] >= max)
         max = b[i];
   return max;
}

int alpha(int* array, int s){
   //some stuff with initial array
   for(int i = 0; i < s; ++i)
      array[i] = 5 * array[i];
			
   //call array from alpha(), not main()
   return beta(array, s);
}
  

int main(){	
   //declare and fill an array of integers
   int array[6] = { 2, 3, 5, 7, 11, 13 };
	
   //find array size
   int size = sizeof(array) / sizeof(int);
	
   //call initial array
   int maxNum = alpha(array, size);
   cout << "arrayMax = " << maxNum << std::endl;
   
   return 0;
}
arrayMax = 65
Thanks i get idea condor
Topic archived. No new replies allowed.