Function Description in C ++

Source: Internet
Author: User

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:

 
 
  1. #include <iostream.h> 
  2.  
  3. #include <math.h> 
  4.  
  5. void main()  
  6.  
  7. {  
  8.  
  9. float f;  
  10.  
  11. cout << "Enter a real number:";   
  12.  
  13. ch >>f;   
  14.  
  15. cout <<”"he square root of" << f << "is" << sqrt(f);  
  16.  

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:

 
 
  1. #include <iostream.h> 
  2.  
  3. #include <math.h> 
  4.  
  5. void main()  
  6.  
  7. {  
  8.  
  9. float f;  
  10.  
  11. cout << "Enter a real number:";   
  12.  
  13. ch >>f;   
  14.  
  15. cout <<”"he square root of" << f << "is" << sqrt(f);  
  16.  

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.

  1. How to Write C ++ project development and project plan correctly
  2. Summary Notes on learning and exploring C ++ library functions
  3. In-depth demonstration of high security of C ++
  4. Describes in detail how to accurately Write C ++ languages.
  5. In-depth demonstration of high security of C ++

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.