So, I tried 3 simple codes on array
// SPDX-License-Identifier: MIT
pragma solidity 0.8.7;
contract test{
uint[] public x;
function testing() public {
x[0] = 20;
}
}
This throws an error but if i use x.push(20) instead of x[0] = 20 then it works OR.....
if I declare the array as
uint[3] public x;
and then use x[0] = 20 inside the function
then it works .... OR..... if I write it as :
uint[] public x = [1,2,3];
and use x[0] = 20 inside the function
then also it works... I dont understand the mechanism behind it