0
Follow
0
View

C//swap does not work

dianhaosu 注册会员
2023-02-27 19:07

I realized that my function was just swapping parameters without affecting the arguments.

dtcnpc 注册会员
2023-02-27 19:07

Why do I need to add the address character?

evold0825 注册会员
2023-02-27 19:07

Changing the parameter does not change the argument
If you need to change the argument, the argument type should be a pointer

duguqiangwei 注册会员
2023-02-27 19:07

All arguments to the C function are passed as a "value call", which means that the function gets a copy of the parameter values. If you need to change the value of an argument, the argument type should be a pointer. In this case, you need to add an address.

e_and_a 注册会员
2023-02-27 19:07

Line 4 with & before x and y;
because it does not use the reference symbol & What is changed is only the substitute of x and y, not the change itself. Plus & If you don't use a surrogate, changes inside the function affect itself.

denny523 注册会员
2023-02-27 19:07
< div class = "md_content_show e397 data - v - 3967" = "" >

ok thank you

About the Author

Question Info

Publish Time
2023-02-27 19:07
Update Time
2023-02-27 19:07