What is the difference between C++ function calls and Struct and CLass
This article introduces the knowledge of "what is the difference between C++ function calls and Struct and CLass". In the operation of practical cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
I. structural review
Structure: the custom data type is defined by Struct regardless of the structure in C++. Compared with the structure in C, the structure in C++ not only has member variables, but also defines member functions (or methods).
Code:
Struct Student {int number; / / member variable char name; / / member variable void num () / member function (method) {number++;}}
The influence of three methods of calling function on the value of structure member variable:
1. Call by passing value
A way to call "structure variable" as a function parameter
/ / void func (Student temp) / / "structure variable" is called as a function parameter (value passing) {temp.number = 2000; strcpy_s (temp.name, sizeof (temp.name), "lisi"); / / by adding monitoring, we can see that the memory address of the formal parameter structure variable temp has changed to 0x00d7fbe4 return;} int main () {Student student Student.number = 1001; strcpy_s (student.name, sizeof (student.name), "zhangsan"); func (student); / / by adding monitoring, you can see that the memory address of the argument structure variable student is 0x00d7fd20 cout