Contoh Kaus dan Jawaban
C++ Passed Value
Berikut adalah contoh program passed value c++.Program ini saya susun atas dasar logika saya,jika ada kesalahan mohon dikoreksi ya sob.
Studi kasus :
#include <iostream>
using namespace std;
int p(int x,int y)
{
return x * y;
}
int main ()
{
int x = 10; //syarat :
int y = 20; //nilai "x" menjadi 20
int z = 5; //nilai "y" menjadi 5
int temp; //nilai "z" menjadi 10
cout <<"parse value\n";
cout <<"Nilai X = "<<"[" << x << "]" <<"\n";
cout <<"Nilai Y = "<<"[" << y << "]" <<"\n";
cout <<"Nilai Z = "<<"[" << z << "]" <<"\n";
temp = x;
x = y;
y = z;
z = temp;
cout <<"Pertukaran nilai\n";
cout <<"Nilai X = "<<"[" << x << "]" <<"\n";
cout <<"Nilai Y = "<<"[" << y << "]" <<"\n";
cout <<"Nilai Z = "<<"[" << z << "]" <<"\n";
cout <<"Hasil perkalian X dan Y =" << p(20,5) <<"\n";
cout <<"Hasil perkalian Y dan Y =" << p(5,5) <<"\n";
cout <<"Hasil perkalian Z dan y =" << p(10,5);
}
using namespace std;
int p(int x,int y)
{
return x * y;
}
int main ()
{
int x = 10; //syarat :
int y = 20; //nilai "x" menjadi 20
int z = 5; //nilai "y" menjadi 5
int temp; //nilai "z" menjadi 10
cout <<"parse value\n";
cout <<"Nilai X = "<<"[" << x << "]" <<"\n";
cout <<"Nilai Y = "<<"[" << y << "]" <<"\n";
cout <<"Nilai Z = "<<"[" << z << "]" <<"\n";
temp = x;
x = y;
y = z;
z = temp;
cout <<"Pertukaran nilai\n";
cout <<"Nilai X = "<<"[" << x << "]" <<"\n";
cout <<"Nilai Y = "<<"[" << y << "]" <<"\n";
cout <<"Nilai Z = "<<"[" << z << "]" <<"\n";
cout <<"Hasil perkalian X dan Y =" << p(20,5) <<"\n";
cout <<"Hasil perkalian Y dan Y =" << p(5,5) <<"\n";
cout <<"Hasil perkalian Z dan y =" << p(10,5);
}
output dari program tersebut