Call by Value/Call by Reference
1. Call by Value
#include <iostream>
void modifyValue(int x) {
x = 20; // Modify the copy of the value
}
int main() {
int a = 10;
std::cout << "Before function call: a = " << a << std::endl;
modifyValue(a); // Passing a by value
std::cout << "After function call: a = " << a << std::endl;
return 0;
}2. Call by Reference
Understanding the Difference
Comparison: Call by Value vs. Call by Reference
Example with Both Methods
Summary
Last updated