The function basis of HLW's C + + learning notes

Source: Internet
Author: User

Local variables

The local variables in the function have common local variables and two kinds of local static variables .

A normal local variable is a variable that is normally defined inside a function body, and if the address of a local variable is returned so that it continues to be accessed after the function call ends, the compiler will report warning itself, which is also wrong because the memory of the variable will be freed after the function call ends.

A local static variable is assigned an initial value at the time of the first definition, and the value in the subsequent call remains the same.

For example

int print () {
static int a = 1;
printf ("%d\n", a++);
}

Parameter passing

The following rules are summed up

1. If it is a normal parameter, the rule is equal to the assigned value.

2. If it's a quote,

(1) The normal reference parameter must satisfy the matching principle, for example, if the formal parameter is an int, then the pass argument can only be int, not double or const int.

(2) A constant reference parameter can pass all the parameters of a very good match, and it can pass all the const type's matching parameters (such as the value of an expression, the return result of the function, etc.).

3. Pointer reference

(1) The difference between normal pointer and regular pointer transfer is only

The function basis of HLW's C + + learning notes

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.