That's great! If we apply what you wrote to your more complex problem with linked lists though, what you're doing is equivalent to doing deep copying. Granted, in this simplified version it is shallow and isn't really copying, but essentially that's the equivalent when your linked lists are involved.
What I thought you might be going for was something like this:
Code:
number *add(number *x, number *y) {
x->value += y->value;
return x;
}
number *multiply(number *x, number *y) {
x->value *= y->value;
return x;
}
So instead of allocating space for a new number, we just change the first argument. If you don't need the original value of the first argument, this would be more efficient.
No, you don't. You can put it here, and if someone copies it, you have proof right here that you wrote it. Other community members might be interested to help you too, and it effectively becomes a matter of public record that you sought help to do your own work rather than getting someone else to do it for you.
Given what you showed me for the simplified example, I'm more convinced that you need to do deep copying.
There's another thing to think about
: get your code working, even if it is inefficient, and then improve it. Should you fail to improve it, at least you can submit your working code.