From 9be584d6939b9b45e3f618525e423e1879acae1e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=95=B0=E6=8D=AE=E7=BB=93=E6=9E=84=E4=B8=8E=E7=AE=97?= =?UTF-8?q?=E6=B3=95?= <79046100+qq1007015993@users.noreply.github.com> Date: Mon, 15 Nov 2021 19:05:45 +0800 Subject: [PATCH] =?UTF-8?q?cpp=2005=E6=95=B0=E7=BB=84=E4=B8=AD(Array=5Fgp.?= =?UTF-8?q?c=E6=96=87=E4=BB=B6=E4=B8=AD=20arrayEmpy=E5=87=BD=E6=95=B0)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 要将数组清空,并且将指针置为空指针,则应该用二级指针来修改。 --- c-cpp/05_array/Array_gp.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/c-cpp/05_array/Array_gp.c b/c-cpp/05_array/Array_gp.c index 0147a121..ee10e10a 100644 --- a/c-cpp/05_array/Array_gp.c +++ b/c-cpp/05_array/Array_gp.c @@ -275,4 +275,17 @@ void arrayDelIndex(Array *array, size_t pos) } --array->len; -} \ No newline at end of file +} +//要将指针array的值置为0,应该用二级指针 +void arrayEmpty(Array** array) +{ + if (NULL == array) + { + return; + } + + free((*array)->p); + (*array)->p = NULL; + free(*array); + *array = NULL; +}