#include <iostream>
using namespace std;
// call by reference - reference argument
void addWithTwo(int &);
void addWithTwo(int &ref){
ref = ref + 2;
}
// call by reference - pointer argument
void addByTwo(int *);
void addByTwo(int *ptr){
*ptr = *ptr + 2;
}
int main()
{
int a = 10, b = 11;
addWithTwo(a);
addByTwo(&b);
cout << "Value of a: " << a << endl;
cout << "Value of b: " << b << endl;
return 0;
}
using namespace std;
// call by reference - reference argument
void addWithTwo(int &);
void addWithTwo(int &ref){
ref = ref + 2;
}
// call by reference - pointer argument
void addByTwo(int *);
void addByTwo(int *ptr){
*ptr = *ptr + 2;
}
int main()
{
int a = 10, b = 11;
addWithTwo(a);
addByTwo(&b);
cout << "Value of a: " << a << endl;
cout << "Value of b: " << b << endl;
return 0;
}
No comments:
Post a Comment