Sunday, September 11, 2011

Array arguments are passed to function by reference

example:
Array arguments are passed to function by reference

#include <iostream>

using namespace std;

void function(int ArrayPassed[], unsigned len);

int main()
{
int array[] = {1, 2, 3, 4, 5};
unsigned length = 5;

cout << endl << "before fnction()" << endl;
for(unsigned i = 0; i < length; i++){
cout << array[i] << " ";
}
function(array, length);

cout << endl << "after fnction()" << endl;
for(unsigned i = 0; i < length; i++){
cout << array[i] << " ";
}

cout << endl;
return 0;
}

void function(int ArrayPassed[], unsigned len){
for(unsigned i = 0; i < len; i++){
ArrayPassed[i] *= ArrayPassed[i];
}
}


No comments:

Post a Comment