I have following homework exercise from lecture "Variables, references and pointers":
Write the function zero (...) so that the following code works correctly: int x = 3; zero(x); cout << x << endl; // writes 0
This is my solution:
#include <iostream>
using namespace std;
void zero(int &);
int main(void) {
int x = 3;
zero(x);
cout << x << endl;
return 0;
}
void zero(int & num) {
num = 0;
}
What do you think about it?