Loading....
Coupon Accepted Successfully!

 

Calling Function with Arrays

  • When an array argument is passed to a function, C++ handles it somewhat differently.

  • When an array is used as an argument to a function, only the address of the array gets passed, not a copy of the entire array.

  • When you call a function with an array name, a pointer to the first element in the array is passed into the function.

  • This means that the parameter declaration must be of a compatible type.

  • There are three ways to declare a parameter that is to receive an array pointer.

Program

#include<iostream.h>

void display(int a[10]);

int main()

{

int age[10],I;

cout<<"enter the elements:\n";

for(i=0;i<10;i++)

cin>>age[i];

display(age);

return 0;

}

void display(int a[10])

{

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

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

}





Test Your Skills Now!
Take a Quiz now
Reviewer Name