14. function value passing and pointer passing

Source: Internet
Author: User
------------
When passing parameters to a function, generally, when passing a non-const pointer, it indicates that the pointer needs to be modified in the function to refer to the data in the memory. If the value is passed, no matter how this value is modified inside the function, it does not affect the passed value, because the passed value is only copied to the memory.

What? You understand this feature. Okay, let's take a look at the following routine:

Void
Getversion (char * pstr)
{
Pstr = malloc (10 );
Strcpy (pstr, "2.0 ");
}

Main ()
{
Char * ver = NULL;
Getversion (VER );
...
...
Free (VER );
}

I promise that such a problem is the easiest mistake for a newbie.ProgramIn the attempt to allocate space to the pointer ver through the getversion function, but this method does not have any function at all, because -- this is to pass the value, not to pass the pointer. Maybe you will argue with me. What is the pointer when I tell you? Let's take a closer look. In fact, the pointer is actually passing the value.

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.