Array formal parameters

Source: Internet
Author: User

In the program, because the array is passed to the function as a pointer to the first element, but because the function does not know the size of the array, it is generally used in the process of using the array as a formal parameter in the following ways, its instance code is as follows:

(1) by passing the first element pointer and making the array size

void Print (cont int arr[], size_t nnum)


for (size_t i = 0; I! = Nnum; ++i)

Std::cout << Arr[i] << Std::endl;


void Print (const int *arr, size_t nnum); As in the previous implementation, int arr[] and int *arr mean index group first element pointer

(2) Array reference parameters

void Print (int (&arr) [10]);

The use of this method can be used, but the limitation of the dimension is not very advantageous.


Array formal parameters

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: 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.