0
pragma solidity ^0.4.24;

contract practice {

   int a = 10;

   function trial() public returns (int) {
       return a;
   }

}

2 Answers 2

1

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) {
0

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;
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.