For example, a function chat (link & a); chat (ling * a); the former introduces an address to form a parameter. Can it put a pointer Variable p .. So using chat (p); what is the difference between it and the second function? It is the transfer address .. The younger brother cannot understand ~~
Chat (int & a); chat (int * a); these two functions have completely different meanings, your understanding is mainly on the int & a and int * a types. Note that int & and int * are two completely different types. Int & is the reference type, while int * is the pointer type pointing to int type variables. Void chat (int & a) {a = 20;} calls this function: int x = 100; chat (x); // at this time, the value of x changes to 20 if the function is as follows: void chat (int * a) {* a = 20;} call: int x = 10; chat (& x); // The value of x also changes to 20; they have a connection, that is, they can change the value of the external variable in the function, but the two parameters are passed in a different void chat (int &) this function is passed by reference, while void chat (int * a); this function is passed by value (although the passed value is an address value, it is still passed by value ). How should this reference type be understood? I understand it like this: int a = 100; so what is a thing about a? Let's say that a makes a variable we define, so what is a variable, I don't know if you have thought about it. We don't talk about the compilation principle, but you can think of a as such. a represents a piece of memory space. Note: it is a piece of memory space, that is to say, this memory space may consist of one or more bytes. In VC ++ 6.0, int-type variables occupy four bytes, therefore, a represents a four-byte continuous memory space. After int & B = a; defines this sentence, B and a both represent the four bytes of memory space. Let's look at int * c = & a; what is c at this time? C also represents a piece of memory space. In VC ++ 6.0, int * type variables occupy 4 bytes of memory space, therefore, c represents a four-byte continuous memory space, and the value put inside it is the address value of the first byte of the memory space represented by. Therefore, when we pass parameters to chat (int & a), such as chat (x), a and x also represent a memory space, while chat (int * a) calls: chat (& x); in this case, the value in a is & x, that is, x represents the first address of the memory. So you need to understand that they do not pass all addresses !!!!! In C ++, the address and reference are not one thing !!!