1. Storage 数组
- 固定长度数组没有push 和 pop
```json pragma solidity ^0.7.0;
contract A{ uint256[] public numbers; // 动态长度数组 address[10] private users; // 固定长度数组 uint8 users_count ;
function addUser (address _user) external {
require(users_count <10 ,"number of users is limited to 10 ");
users[users_count] =_user;
users_count ++;
}
fucntion addNumber(uint256 _number) external {
numbers.push(_number);
}
}
<a name="bcUfo"></a>
## 2.Memory 数组
1. 这些数组以 memory作为其数据位置声明。
1. 它们也可以具有固定长度或动态长度,但是不能调整动态大小的内存数组的大小(即,不能调用push()和pop()方法),
uint256[20] memory numbers; 就像这里20这个位置必须是常量
3. 数组的大小必须预先计算。
3. 使用new关键字声明动态大小的内存数组,如下所示 Type[] memory a = new Type[](size)
<a name="E9jvq"></a>
### 特别注意:
如果这样写,你不会收到任何警告,但最终将得到无效的操作码,因为根据内存中布局的描述,array将指向零插槽,因此切勿写入。请记住,在使用数组之前,请务必先对其进行初始化,以便获取有效的地址。
```json
uint256[] memory array;
array[0] = 1;