Recording Session


Call By Value

#include <iostream>
using namespace std;

void changeValue(int a){
    a = 1;
}

int main(){
    int x = 0;
    int y = 9;
    
    changeValue(x);
    cout << x + y;
}

Output

9

Call By Reference

#include <iostream>
using namespace std;

void changeValue(int &a){
    a = 1;
}

int main(){
    int x = 0;
    int y = 9;
    
    changeValue(x);
    cout << x + y;
}

Output

10

Call By Address

#include <iostream>
using namespace std;

void changeValue(int *a){
    *a = 1;
}

int main(){
    int x = 0;
    int y = 9;
    
    changeValue(&x);
    cout << x + y;
}

Output

10