Array as function parameter

Source: Internet
Author: User

1. One-dimensional array name function parameters

Using array names as function parameters, you should define arrays in the main and called functions, for example

<Span style = "font-size: 18px;"> void main () {void F (int B [10]); // void F (int B []) int A [10]; F (a) ;}</span>

In the called function, it is declared that the size of the parameter array is 10, but in reality, it does not have any effect to specify the size, because the C language compilation does not check the size of the parameter array, only the first element address of the real parameter array is passed to the form parameter array. You can leave an empty square brackets behind the defined array, as shown in. In addition, when using an array name as a function real parameter, instead of passing the value of the array element to the form parameter, the address of the first element of the real parameter array is passed to the form parameter array.

Ii. Multi-dimensional array name function parameters

The multi-dimensional array name can be used as the real parameters and form parameters of the function. when defining the form parameter array in the called function, the size of each dimension can be specified, or the size of the first dimension can be omitted. For example, the description of int array [3] [10] Or int array [] [10] cannot be omitted, int array [] [] is invalid. If the size of the second dimension is the same, when the form parameter array and the real parameter group are different in the first dimension, the form parameter array and the real parameter group are composed of one-dimensional arrays of the same size, C language compilation does not check the size of the first dimension.

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.