Reference Parameter Update

#include <iostream>
#include <cstdint>

// The '&' here tells C++ that x is an alias for the actual variable in main
void update(int32_t& x, int32_t delta) {
    x += delta; // This modifies the original x
}

int main() {
    int32_t x, delta;
    
    if (!(std::cin >> x >> delta)) return 0;

    // Call the function WITHOUT the '&' symbol.
    // C++ knows to treat it as a reference because of the function definition.
    update(x, delta);

    std::cout << x;

    return 0;
}

Solving Approach

 

 

 

 

Upvote
Downvote
Loading...

Input

10 4

Expected Output

14