What is the format for functions? #766
-
He uses function store(uint256 _favoriteNumber) public { to store the variable, but he uses function retrieve() public view returns(uint256) { to return it. Is the "store" in the first piece of code and "retrieve" in the second piece the name of the function? If it is, then why does one of them have something in the parenthesis and the other one doesn't? For the second piece of code, why do you have to specify twice that you are returning a number ("returns(uint256)" and "return favoriteNumber")? What is the format of functions? This is the first time I have ever coded, so I barely know anything. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Hello @DatBigChungo Each language has its rules, in solidity case you specify each variable type, and also it's length (uint256 for example) because the EVM has limited resources and must know how to deal with the code. I hope this info might help. |
Beta Was this translation helpful? Give feedback.
Hello @DatBigChungo
Yes "store" and "retrieve" are the name of the functions. The reason on of them has something in the parenthesis is because is a input parameter.
On the function declaration you specify which type of variable you are returning, and when you say
return favoriteNumber
you are saying which is the variable you are going to return which has to be the same type as your declared.Each language has its rules, in solidity case you specify each variable type, and also it's length (uint256 for example) because the EVM has limited resources and must know how to deal with the code.
I hope this info might help.