In C, the statement that declares an array:
int arr[];
So the declared array is stored in random data that we don't know, which is garbage to the user. There are many situations where we want to initialize an array to all zeros in order to do something else.
The simplest way to do this is to use a looping bar array to set all elements to 0:
int arr[]; int 0 ; for 0 ; i++) 0; // This would make all ZERO
There are several other ways we can initialize an array to 0:
1, global variables and static variables are automatically set to 0 when initialized. If you declare a global variable, then he will become full 0 before running.
int arr[1024x768// This is globalint main (void) { // Statements}
2, for the local array we also have shorthand initialization syntax. If an array is partially initialized, elements that are not initialized are automatically set to the corresponding type of 0. This is done automatically by the compiler. It can be written like this:
int Main (void) { int arr[1024x768] = {0}; // This would make all ZERO // Statements}
3 . You can also initialize the array with the Memset function at the beginning of the program. This command is especially useful if you have modified the array and want to reset it to full 0.
int arr[1024x768];arr[501024x768// This would reinitialize all to ZERO
How do I initialize an array to a full 0?