Code:
#include<iostream.h>
// this function will modify the passed in values without having to return anything
void refPassFunc( int &, char &);
int main(void) {
int userInt;
char userChar;
cout << "Please enter a integer : ";
cin >> userInt;
cout << "Please enter a character : ";
cin >> userChar;
cout << "You have inputted " << userInt << " and " << userChar << endl;
refPassFunc( userInt, userChar );
cout << "The new values are " << userInt << " and " << userChar << endl;
return 0;
}
void refPassFunc( int &intIn, char &charIn ) {
// will add 6 to the number being passed in
intIn += 6;
// will set the character to 'H'
charIn = 'H';
}
Passing by reference will pass the location of the variable instead of the variable's value. This means that when the function modifes the value of its variable, it is actually modifing the initial passed variable. Phew.
A quick note, all arrays are automatically passed by reference.