Passing data by value between C and C++
In general, value parameters are passed and received by C++ in the same manner as under C; a non-pointer or reference variable is passed in the parameter list. Any change that happens to a value parameter in the called function does not affect the variable in the caller, as in the following example, where an integer is passed by value from C++ to C:
Sample C++ usage | C subroutine |
---|---|
|
|
Similarly, to pass an int by value from C to C++:
Sample C usage | C++ subroutine |
---|---|
|
|