当前位置:网站首页>Error: error summary of pointer as function parameter

Error: error summary of pointer as function parameter

2022-06-11 17:01:00 NI3E

We know , The arguments passed by the function are “ Copy ”, It is not to pass in the original value , Unless the parameter is an array “ Address ”.

When you pass a pointer as a function parameter , Take it for granted that the pointer has been modified in the function , Keep pointer changes outside the function .

actually , After calling the function , The pointer does not change .

So you can point to the new pointer as the return value , Change the original pointer to by assignment . To modify the pointer .


2021-6-12 Add

In use C Write stack and list All the time .

Already know “ When a pointer is passed in as a function parameter , Modified the pointer in the function , The pointer outside the function does not change , You need to use the return value to change the original pointer to ”. But the last time I didn't write down the problems I really encountered .

When I want to change the chain structure , Adopted move Function calculates the next position allowed by the algorithm , Then proposed int Type stores the number of steps , But in fact, we need to ensure that the pointer always points to the desired position when the function is running (Head or tail), therefore , When nesting functions , We always need to ensure that the return value is a pointer , Can be in main The position of the pointer inside is normal . therefore move It calls the function to change the direction ,move The return value needs to be a pointer .

in other words , When it comes to the pointer problem of this linked list , Nested functions should satisfy that the return value is a pointer . And every call is “ The pointer = function ( The pointer )” In the form of , Every floor should be like this .

原网站

版权声明
本文为[NI3E]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/162/202206111651540444.html