Although not commonly used, if used to find them much more convenient.
1.memset function: assign the same value for each element of the array (the assignment byte - byte each assigned the same value)
Memset (array name, value, sizeof (array name))
* void * Memset (void , int, size_t);
Indispensable string.h header file.
Recommended assignment: 0 / -1. Because memset function is a byte assignment, the full complement of 0 is 0, 1 full complement -1, less error prone.
#include"stdio.h"
#include "string.h"
int main() {
printf("赋值前:");
int a[5] = {1, 3, 5, 10, 7};
for (int i = 0; i < 5; i++)
printf("%d ", a[i]);
memset(a, -1, sizeof(a));
printf("\n赋值后:");
for (int i = 0; i < 5; i++)
printf("%d ", a[i]);
}
Test results: