1. C ++ series functions,

Source: Internet
Author: User

1. C ++ series functions,

Reference: http://www.cplusplus.com/doc/tutorial/functions/


Value Transfer and reference Transfer

  • Value Transfer refers to the parameter passed by the function, which is a specific value (number, String, etc.). When the function body operates these valuesNoChange these parameter values.

  • Reference transfer refers to the parameter passed by the function as a variable, and "variable" can be changed, so the function body operates on these variables at the same time.YesChange it.

  • What can be solved by reference transfer? When the parameters to be passed take up a lot of space, the efficiency will be very low if the value transfer method is adopted. For example, I uploaded a file of more than 10 GB to the function for processing, because it needs to copy these files to the function, the speed is very slow, but the reference transmission method can solve this problem, because only the variable name is passed.
  • What if I want to pass the parameter via reference but do not want the function to change the value of the parameter? Just change it to a constant reference. Add the const keyword before each parameter type that you do not want to change, such as void duplicate (const int & a, const int & B, const int & c)


Inline functions

  • Inline functions are mainly used to solve the problem of function calling efficiency and save the overhead of function calling at the cost of space. It can be understood that inline functions are small functions, generally, these functions do not have loops or conditional statements, which can replace macro definitions in C.
  • You can add the keyword inline before the function declaration.

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.