Pass an Array by Reference in C++



If we pass the address of an array while calling a function, then this is called function call by reference. The function declaration should have a pointer as a parameter to receive the passed address, when we pass an address as an argument.

Example Code

 Live Demo

#include <iostream>
using namespace std;
void show( int *num) {
   cout<<*num;
}
int main() {
   int a[] = {3,2,1,6,7,4,5,0,10,8};
   for (int i=0; i<10; i++) {
      show (&a[i]);
   }
   return 0;
}

Output

32167450108
Updated on: 2019-07-30T22:30:25+05:30

6K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements