Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and beauty - How to clear array in C language
How to clear array in C language
There are two ways to achieve this. For the convenience of explanation, the integer array a is defined and cleared. inta[4]={ 1,2,3,4 }; 1, through array traversal, assign values to 0 one by one. Define the loop variable intifor(I = 0;; I<4; i++)a[I]= 0; The function of this program is to traverse the array A and assign the elements to 0 one by one, thus achieving the effect of emptying. 2. With the help of the memory assignment function memset, the overall assignment is 0. void*memset(void*dst,intvalue,size _ tsize); The function is used to assign the size byte data on src. It should be noted that the assignment of this function is in bytes. When calling this function, you need to refer to the header file string.h, which is # include.