+ 1
Call by value vs Call by reference.
Can anyone differentiate b/w the two?
3 odpowiedzi
+ 5
call by value passes d copy of a value in a variable which means it wont modify/change the original value of a variable
while
call by reference passes d orginal value of a variable. which means it will modify/change the original value of a variable.
void printValue(int );
void printRef (int*);
int val = 5;
int ref = 7;
int main ()
{
printValue(val);
printRef (&ref);
cout << val; //prints 5
cout << ref; //prints 10
return 0;
}
void printRef(int *r)
{
ref = r + 3;
}
void printValue(int v)
{
val = v + 3;
}
+ 1
Thanks Raj. I am here to help
0
nice explanation Franky, 👍, it helps, keep up the good work