Modify pointer address

Source: Internet
Author: User

You can see the correct question below:

Void GetMemory (char * p) {p = (char *) malloc (100 );}

Void Test (void)
{
Char * str = NULL;
GetMemory (str );
Strcpy (str, "hello world ");
Printf (str );
}

No response. I don't know where the problem is. I suspect there may be a problem with the GetMemory function. The answer is:The input parameter of the GetMemory (char * p) function is a string pointer. Modifying the parameter inside the function does not actually change the value of the input parameter.I don't know much about this sentence, because the first reaction is in conflict with the concept in my mind. In programming, I always pass in pointers or references to modify and compute external variables in the function, why do we need to talk about this? So I checked the information again. It turned out to be like this. When you want to modify the value pointed to by the pointer, you can pass the pointer. However, when you want to modify the pointer address, such as allocating an address area, you need to input a pointer reference or pointer. These two points reflect the flexibility of the pointer language.

 

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.