// more than one returning value
void prevnext (int x, int& prev, int next)
prev = x-1;
next = x+1;
int main ()
int x=30, y, z;
prevnext (x, y, z);
cout << "Previous=" << y << ", Next=" << z;
I don't understand the question. If z is not changed, then why would you expect it to output 30?
Or perhaps more to the point, if that's what you want to happen, the code must be modified to make it so. The most straightforward way would be to pass z by reference. That is change function prevnext() to pass next in the same way as prev.