Nice solution @jCA
In actual fact, defining a local variable in memory
consumes more gas because it creates a separate copy of the User instance. Your solution, and also the alternative which turns the local variable into a “pointer” by changing memory to storage, are both cheaper in terms of the gas cost, and both consume more or less the same amount of gas, because they effectively perform the same low level operations.
Also, for your next assignments, please don’t post screen shots, because we can’t copy and paste your code in order to execute and test it, if we need to. Instead, follow the instructions in this FAQ: How to post code in the forum .
Just let me know if you have any questions