Meaning of pass by reference in C and C++?

后端 未结 10 1115
生来不讨喜
生来不讨喜 2020-12-17 20:46

I am confused about the meaning of \"pass by reference\" in C and C++.

In C, there are no references. So I guess pass by reference means passing a pointer. But then

10条回答
  •  不知归路
    2020-12-17 21:41

    when you pass something by reference you're working with the address and not the value of a variable directly, If you use a reference parameter you're getting the address of the variable you pass in.

    From there you can manipulate it how ever you want as the variable you passed in WILL change if you change the reference in the function. It's an easier way to work with large amounts of a data it really just saves on memory etc..

提交回复
热议问题