Destroying Array
时间: 2023-11-16 10:53:11 浏览: 36
To destroy an array in C, you can use the `free()` function to deallocate the memory occupied by the array. Here's an example:
```c
#include <stdlib.h>
int main() {
int* arr = malloc(5 * sizeof(int)); // dynamically allocate memory for the array
// Use the array here...
// Destroy the array
free(arr);
arr = NULL;
return 0;
}
```
After calling `free(arr)`, the memory allocated for the array is released back to the system, and `arr` is set to `NULL` to avoid any potential access to the now-deallocated memory.
Related questions:
1. How does the `free()` function work in C?
2. Can I destroy individual elements in an array without destroying the entire array?
3. What happens if I try to access a destroyed array in C?