On the knowledge of C language parameter transfer

Source: Internet
Author: User

C is not like an object-oriented language, there are no overloads, no overrides.

C language passed parameters if it is a pointer, it is only an address, remember just the address.

#include <stdio.h>
#include <stdlib.h>

void Test (char *buf, int len)
{
        printf sizeof ( BUF) =%d, len=%d\n ", sizeof (BUF), Len);
}
int main (void)
{
        char buf[10];
        Test (buf, sizeof (BUF));
        return 0;
}

weeds@weeds-laptop:~/love$./param
sizeof (BUF) =4, len=10


The results of the implementation are as follows.

Analysis of the reasons:

BUF[10], located in memory on the heap, is a contiguous area of memory.

My theoretical knowledge can not explain this, who explained the next chant.

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.