Library functions in C Language (continuously updated)

Source: Internet
Author: User

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 '.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.