The array name is degraded to the pointer __ function as a function argument

Source: Internet
Author: User


void arraysum (int a[],int b[])
{
cout < < "sizeof (a)" < <sizeof (a) < <endl;
cout < < "sizeof (A[0])" < <sizeof (int) < <endl;
int length_a = sizeof (a)/sizeof (int);


}


Equivalent to:
void arraysum (int *a,int *b)
{
cout < < "sizeof (a)" < <sizeof (a) < <endl;
cout < < "sizeof (A[0])" < <sizeof (int) < <endl;
int length_a = sizeof (a)/sizeof (int);


}


Recently wrote a few small functions, useful to the array name as a parameter of the case, here to record the learning process.

Some knowledge: http://www.cnblogs.com/c-king/archive/2009/03/05/1404202.html

The parameters of the array masterpiece function must follow the following guidelines:
(1) If the formal parameter is an array, the argument must be the actual array name, and if the argument is an array name, then the parameter can be an array name or a pointer to the same number of dimensions.
(2) To define the array separately in the keynote function and the modulated function.
(3) The real parameter group and the parameter group must be of the same type, and the parameter group can not indicate the length.
(4) in the C language, the array name, except as the identifier for the variable, the array name also represents the starting address of the array in memory, so when the array masterpieces function argument, the actual participating parameter is not "value pass", but "address delivery", and the real parameter group name is passed the starting address of the array to the form parameter group. Two arrays share a memory unit, and the compilation system no longer allocates storage units for the parameter groups.

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.