23.8k views
0 votes
In C++, arrays can be passed as parameters to a function either by value or by reference.

Select one:

True

False

User Stasiekz
by
5.8k points

1 Answer

6 votes

Answer:

The statement written is True.

Step-by-step explanation:

In C++ you can pass arrays to function as parameters either by value or by reference.

Following is the example of both cases.

#include <iostream>

using namespace std;

//array passed by value

void printarray(int a[],int n)

{

for(int i=0;i<n;i++)

cout<<a[i]<<" ";

cout<<endl;

}

//array passed by reference

void printarrayp(int *a,int n)

{

for(int i=0;i<n;i++)

cout<<a[i]<<" ";

cout<<endl;

}

int main() {

int arr[100],size;

cin>>size;

for(int i=0;i<size;i++)

cin>>arr[i];

printarray(arr,size);

printarrayp(arr,size);

return 0;

}

Input:-

6

1 2 3 4 5 6

Output:-

1 2 3 4 5 6

1 2 3 4 5 6

In function printarray.The arrays is passed by value and in function printarrayp the array is passed by reference.

User Anton Podolsky
by
6.8k points