C + + supplements (vi) function-related

Source: Internet
Author: User

return value

C + + Specifies that the return value cannot be an array. But it can be any other type (including structs and objects).

Typically, the function copies the return value to the specified CPU register or memory cell, and then calls the function to call the value of the memory cell.

Function prototypes

Variable names can be excluded from the argument list, and variable names in the prototype are equivalent to placeholders, and do not need to be the same as in a function definition.

In C + +, NULL in the prototype () means no parameters, (...). ) means that the prototype does not specify a parameter list, and the parameter list is defined after the prototype.

Typically, the prototype automatically casts the passed argument to the desired type, provided that both are arithmetic types.

function parameters

When declaring multiple arguments, you cannot combine declarations like declaring variables, such as: float A, b; It is possible to declare a variable, but void function (float a, b) is illegal and should be

void function (float A, float b).

Function Pass Array

1 void int int length);

Where array is the address of the first element of the incoming array, this is beneficial: saving time and memory for copying the entire array. There are also disadvantages: there is a risk of destroying the original data.
Also, when passing an array, the length of the array needs to be passed separately, and the length of the pointer variable will be obtained using sizeof (array) in the function.

To prevent changes to the original data, you can precede the parameter with the const keyword.

1 void Const int int length);

The raw data is not necessarily constant, but for function, the raw data is read-only.

C + + supplements (vi) function-related

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.