A function is a major component of a C ++ program. A function can call other functions. In a well-designed program, each function has a specific purpose. This article will analyze and introduce the functions in C ++ that most users have a headache.
The function can be repeatedly used only once, which greatly simplifies the programming process. The C ++ System Library provides hundreds of functions for programmers. This section describes several issues that should be paid attention to when using system functions. It also describes how to use an important function exit. Programmers should understand the functions provided by the C ++ System for selection as needed. The manual provided with the compiler provides descriptions of functions and usage of various functions.
We know that functions must be defined or described before they can be used in programs. System functions are divided into several categories based on their functions. Each type has a header file, which provides the prototype of each function of this class. Therefore, we only need to use the # include command in the program to embed the corresponding header file, instead of directly describing the function prototype in the program.
The document explains which header file to embed when using a function. For example, to calculate the square root of a number in a program, a corresponding function has been provided in the C 10 library. in the manual, the function description is as follows:
- #include <iostream.h>
-
- #include <math.h>
-
- void main()
-
- {
-
- float f;
-
- cout << "Enter a real number:";
-
- ch >>f;
-
- cout <<”"he square root of" << f << "is" << sqrt(f);
-
- }
When these two programs are compiled, the compiler automatically finds the corresponding header files in the c ++ system directory and embeds them into the program. Many functions are classified as stdlib. h and exit functions. The description of this function is as follows:
- #include <iostream.h>
-
- #include <math.h>
-
- void main()
-
- {
-
- float f;
-
- cout << "Enter a real number:";
-
- ch >>f;
-
- cout <<”"he square root of" << f << "is" << sqrt(f);
-
- }
This function causes the entire program to terminate immediately and return it to the operating system. The value of the parameter is called the exit code, which is used to notify the operating system of the State when the program is terminated. 0 indicates that the program is terminated normally, and non-0 indicates that the program is running incorrectly. When executing a function, the programmer needs to use the exit function to immediately terminate the program and not return it to the caller.
- How to Write C ++ project development and project plan correctly
- Summary Notes on learning and exploring C ++ library functions
- In-depth demonstration of high security of C ++
- Describes in detail how to accurately Write C ++ languages.
- In-depth demonstration of high security of C ++