Professional Documents
Culture Documents
Return Value
Pass By Reference
Pass by Value
Penyalinan nilai dari argumen fungsi
pemanggil ke parameter fungsi yang
dipanggil
argumen dari sebuah fungsi akan
mempunyai nilai seperti semula setelah
eksekusi fungsi.
Contoh 1
int sum(int num_1, int num_2) Meskipun nilai
{ parameter num_1
num_1 = num_1 + num_2; dirubah, argumen yang
return num_1; berhubungan yaitu
} var_x tidak berubah.
void main() {
int I= 10;
}
Pass by Value: Contoh 2
Contoh 3
int feet(int);
int remain_inches(int);
void main() {
int inches; // Number of inches
cout << "Enter number of inches to convert:";
cin >> inches;
cout << "Result is " << feet(inches)
<< " feet " << remain_inches(inches)
<< " inches" << endl;
}
int &foo;
double &blah;
char &c;
Contoh Variable Reference
int count;
int &b = count;
// b adalah variabel yang sama seperti
// count
count = 1;
cout << b is << b << endl;
b++;
cout << count is << count << endl;
Parameter Reference
Deklarasi parameter reference:
Increment(Inc);
SumAve (2.5, y+3, sum, mean);