fix: zero-initialize C++ arrays in documentation (#1936)

Explicitly initialize the array elements to 0 to eliminate potential undefined behavior.
This commit is contained in:
ShenMian
2026-10-10 19:18:12 +08:00
committed by GitHub
parent db6f21aaf5
commit bd46fca90d
+2 -2
View File
@@ -23,10 +23,10 @@
```cpp title="array.cpp"
/* 初始化数组 */
// 存储在栈上
int arr[5];
int arr[5] = {};
int nums[5] = { 1, 3, 2, 5, 4 };
// 存储在堆上(需要手动释放空间)
int* arr1 = new int[5];
int* arr1 = new int[5] {};
int* nums1 = new int[5] { 1, 3, 2, 5, 4 };
```