I just found that when I do 5/2 with assignment operator, it does not give any error immediately and just give the result as 2 instead of 2.5. Would you please let me know why it is ?
// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.7.0 < 0.9.0;
contract Practice {
uint a = 5;
function assignment() public returns(uint){
a /= 2 // no error
return(a) // it returns 2 instead of 2
}
}
// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.7.0 < 0.9.0;
contract Practice {
uint public a = 5/2; // error occured
}
and One more question , when I do declare public to variable, will it be private ?
// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.7.0 < 0.9.0;
contract Practice {
uint a; // Does it become private?
}