Library functions in C Language (continuously updated)
1. [exit ()]
Exit is to forcibly exit the program at the call. Once the program is run, it ends. Exit (0) indicates normal exit. Exit (1) indicates that an exception exits. This 1 is returned to the operating system. Whether written in the main function or in other functions, the program exits. Generally, 0 indicates normal exit, and other numbers indicate abnormal exit. The header file is stdlib. h. The returned value is actually the same as the return value in the main function. Zero indicates normal, and non-zero indicates exception.
2. [memset]
The function declaration is: memset (void *, int, size_t n ). The function is to set all the content of the first n Bytes in a memory (size specified by size_t, which can be calculated using sizeof function) pointed to by void * to the int value. This function usually initializes the newly applied memory. If it is in the linked list, when we apply for a new node, we will also use this function to initialize the node. The sample code is as follows:
# Include "stdio. h "# include" string. h "int main (int argc, const char * argv []) {char str [] =" abcde "; printf (" % s \ n ", str ); memset (str, 0, strlen (str); printf ("% s \ n", str); return 0 ;}
The output is as follows:
.
We can see that the array is actually empty, rather than each element in the array is set to 0.
# Include "stdio. h "# include" string. h "int main (int argc, const char * argv []) {char str [] =" abcde "; printf (" % s \ n ", str ); memset (str, '0', strlen (str); printf ("% s \ n", str); return 0 ;}
The output is as follows:
.
Here, all elements in the array are replaced with the character '0 '.