If C ++ 11 is not possible, you can use links.
Passing a reference to the variables in the parameters.
int DFS(int a, int b, int c, int d, int &cost_limit) { cost_limit = c + d; return a + b; } int solution, cost_limit; solution = DFS(a, b, c, d, cost_limit);
source share