课程: Complete Guide to C++ Programming Foundations

免费学习该课程!

今天就开通帐号,24,100 门业界名师课程任您挑!

Passing values to a function

Passing values to a function

- [Instructor] Now I'd like to take a moment to tell you a bit more about function parameters. In many programming languages, you may pass arguments by value or by reference. C++ implements three variants of this. Normally, arguments are passed by value. This means that inside the function, you'll have copies of the variables sent as arguments. You cannot modify the original variables from the caller scope. You may also pass arguments as pointers. That means that you may send the address of the variable as an argument. This will give you the power to access the variable from inside the function. This may be dangerous, but it's a possibility. And you may also pass arguments as references. This is similar to passing arguments as pointers, but the limitations of references often make this the smart and safe choice. Here we have a simple textbook example for you to see the syntax of these three different ways of declaring your function parameters. I'll create three functions, one that…

内容