链接
parameters 是什么
- 变量名
- 数据从调用环境传递到被调用函数
- 这个过程叫传参
Two ways to pass into a function:
- pass by value
- pass by reference
Pass by value: fundamental type
the parameter is a copy of the original variable
- num1和x在内存的不同位置
- 调用foo时候,只是将20从内存复制到变量x的位置
- return的时候,再把结果拷贝到num2在内存的位置
如上是不会修改主函数中的值,如果想修改主函数中的值,可以参考如下。
Pass by value: pointor
传递的值是p的值,也就是num1de地址。
Pass by value: Structure
修改mat中的rows cols值不会影响外面的。
但是使用mat的pData修改pData指向的内容,会修改外面。
?question
如果结构体很大,怎么传参。