

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!


#include using namespace std; void modifyValue(int num) { num = num + 10 ; // Changes only the copy } int main() { int x = 5 ; modifyValue(x); cout << "Value of x: " << x << endl; // Output remains 5 return 0 ; }
#include using namespace std; void modifyReference(int &num) { num = num + 10 ; // Directly changes the original variable } int main() { int x = 5 ; modifyReference(x); cout << "Value of x: " << x << endl; // Output becomes 15 return 0 ; }