In C language, after the struct pointer is passed into the function, the memory address remains unchanged and the memory data changes.

Source: Internet
Author: User

In C language, after the struct pointer is passed into the function, the memory address remains unchanged and the memory data changes:

Rgbblockinfo_t * rgbblockinfo = NULL;

/* Obtain the address */

Rgbblockinfo = filetorgbbufblock (rgbbufinfo, "d :\\ picdata \ pens. RGB ");

/* Pass the address to the function */

Rgbfilewrite (rgbblockinfo, "d: \ picdata \ pens2.rgb ");

After passing in the function, the memory address remains unchanged, but the data pointed to by the memory address changes.

Before import:

After passing in:

So, as a cainiao, I am wondering where to modify the memory value?

 

I have studied it today. In the filetorgbbufblock function, the local variable rgbblockinfo_t rgbbuf is defined, and the address of the local variable is returned through return.

The problem occurs here because rgbbuf is a local variable and will be released after the function is called. Therefore, the value in the memory will be released.

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.