CodesJava

Easy learning with example program codes

CPP Array to Function


Arguments are the variables, inside the parentheses, after the function name which is used to pass informations to functions. Beside passing variables and pointers, arrays can also be passed as a function parameter or argument.

Syntax:

Return_type functionName (Data_type array Name[])

{

    code to be executed;

}

Example:

#include <iostream.h>
using namespace std;
 
int maximum(int a[],int size)
{    
int max = a[0];    
int i=0;    
for(i=1;i<size;i++)
{
if(max < a[i])  
max = a[i];    
}  
return max;    
}
 
int main()
{ 	 
int i=0,max=0;    
int array[] ={9,52,77,635,889,679,6,54,78,34};
cout << "List of Numbers: " << endl;
 
for(i=0;i<10;i++)
cout << array[i] << endl;
 
max = maximum(array,10);
cout << "Largest Number is: " << max;    
return 0;
}

Output

List of Numbers:
9
52
77
635
889
679
6
54
78
34
Largest Number is: 889
Please follow and like us:
Posted in CPP   


Copyright © 2019 CodesJava DMCA.com Protection Status SiteMap Reference: Java Wiki