// SPDX-License-Identifier: MIT

pragma solidity 0.8.16;

contract test7 {
  function getNum() public pure returns(uint256[4] memory,string memory) {
      string[4] memory _a = ['1','2','3','4'];

      uint256[4] memory a = [1,2,3,4]; // error

      return (a,_a);

What is the difference between string and uint(int) in solidity?

As in the code above, why is uint not like string?

1 Answer 1


String is a datatype that supports using literal single(‘) and double(“ ”) quotes, while uint is a datatype that supports using positive integers. In the code above, uint is not like string due to this error: TypeError: Type uint8[4] memory is not implicitly convertible to expected type uint256[4] memory.

  • I wrote it as uint256[4], why did it suddenly become uint8[4]?
    – imelon2
    Sep 20, 2022 at 9:16

Your Answer

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

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