From 9aa620b24d4fdcfa5b554eab3ecc697e8027ca42 Mon Sep 17 00:00:00 2001 From: ruanyf Date: Mon, 13 Sep 2021 20:40:37 +0800 Subject: [PATCH] docs(array): fixed #28 --- docs/array.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/array.md b/docs/array.md index 758759e..2a079f8 100644 --- a/docs/array.md +++ b/docs/array.md @@ -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`是多少。 变长数组的根本特征,就是数组长度只有运行时才能确定。它的好处是程序员不必在开发时,随意为数组指定一个估计的长度,程序可以在运行时为数组分配精确的长度。