C++ Passing Array To Function Arguments
Passing array to function argument in C++. There are three ways to approach function declaration to receive an array as the function argument.
1st Way:-
Syntax:
return_type function(type array_name[])
Example:
void smart(int par[])
2nd Way:-
Syntax:
return_type function(type array_name[Size])
Example:
void smart(int par[5])
3rd Way:-
Syntax:
return_type function(type *array_name)
Example:
void smart(int *par)
Example:-
#include <iostream> using namespace std; int sumofarrayvalue(int arr[],int size){ int sum=0; for(int i=0; i<size; i++){ sum+=arr[i] ; } return sum; } int main(){ int numbers[]={6,9,1,3,4,8}; int sum; /* Passing pointer to the array as an argument */ sum=sumofarrayvalue(numbers,6); cout << "Sum Of Array Value is " << sum; return 0; }
Quickly Find What You Are Looking For
OnlineTpoint is a website that is meant to offer basic knowledge, practice and learning materials. Though all the examples have been tested and verified, we cannot ensure the correctness or completeness of all the information on our website. All contents published on this website are subject to copyright and are owned by OnlineTpoint. By using this website, you agree that you have read and understood our Terms of Use, Cookie Policy and Privacy Policy.