And now i will show u the difference between by value and by reference in c++ by the below example and you can test it to understand more and more
#include <iostream>
using namespace std;
//declaration the function
/**
- value - passing parameter by value
- @param int
**/
void value(int);
/**
- reference - passing parameter by reference
- @param int& - number to be incremented
**/
void reference(int&);
int main(){
int num = 5;
value(num);
cout << " the value func result is : " << num << endl;
reference(num);
cout << " the reference func result is : " << num << endl;
return 0;
}
//defination the function
void value(int num){
num+=2;
}
void reference(int& num){
num+=2;
}
0 التعليقات :