docs(array): fixed #28

This commit is contained in:
ruanyf
2021-09-13 20:40:37 +08:00
parent 0f66350bf3
commit 9aa620b24d

View File

@@ -203,11 +203,11 @@ int a[2][2] = {1, 0, 0, 2};
数组声明的时候数组长度除了使用常量也可以使用变量。这叫做变长数组variable-length array简称 VLA
```c
int n = a + b;
int a[n];
int n = x + y;
int arr[n];
```
上面示例中,数组`a`就是变长数组,因为它的长度取决于变量`n`的值,编译器没法事先确定,只有运行时才能知道`n`是多少。
上面示例中,数组`arr`就是变长数组,因为它的长度取决于变量`n`的值,编译器没法事先确定,只有运行时才能知道`n`是多少。
变长数组的根本特征,就是数组长度只有运行时才能确定。它的好处是程序员不必在开发时,随意为数组指定一个估计的长度,程序可以在运行时为数组分配精确的长度。