← Back to Course

Lesson 33: Return value from postfix operators

Practice Questions

Question 1: Consider the following code. What value will be returned by this function? The return can be a value or, if revert, type revert.

function f() public pure returns (uint8) {
    uint8 a = 26;
    uint8 b = a--;
    return b;
}

Question 2: Consider the following code. What value will be returned by this function? The return can be a value or, if revert, type revert.

function f() public pure returns (uint8) {
    uint8 a = 10;
    return a++;
}

Question 3: Consider the following code. What value will be returned by this function? The return can be a value or, if revert, type revert.

function f() public pure returns (uint8) {
    uint8 a = 10;
    return a++ + a--;
}

Question 4: Consider the following code. What value will be returned by this function? The return can be a value or, if revert, type revert.

function f() public pure returns (uint8) {
    uint16 a = 255;
    uint8 b = uint8(a++);
    return b;
}

Question 5: Consider the following code. What value will be returned by this function? The return can be a value or, if revert, type revert.

function f() public pure returns (int8) {
    int8 a = 10;
    return -a++;
}