Reference Parameter Update

#include <iostream>

void update(int &x ,int value) {
    x+=value;
    // Implement update logic here
}

int main() {
    int32_t x, delta;
    std::cin >> x >> delta;
     int &alias=x;
    update(alias,delta);

    std::cout << x;   // Print updated value

    return 0;
}

Solving Approach

the reference and variable point to the same memory location 

 

 

 

Upvote
Downvote
Loading...

Input

10 4

Expected Output

14