pragma solidity ^0.4.24;
contract practice {
int a = 10;
function trial() public returns (int) {
return a;
}
}
2 Answers
Functions can either be invoked via transactions or calls. Transactions are used for functions that mutate state, and transactions do not have return values. Calls cannot mutate state but do have return values.
Remix uses a call only when the function has the pure
or view
modifier. Just add view
, and things will work how you expect:
function trial() public view returns (uint) {
Change your function definition to include view
. Then it will return the value of a
in Remix IDE.
function trial() public view returns (int) {
return a;
}