Void f (linklist p)
What is the difference between the two??
CodePudding user response:
Big difference, the former is address (although it is disguised addressing), the latter is the value transfer (pointer to pass also belong to value)LZ test, which function parameters in the address and the main function of variable address?
void t1 (int & amp; A) {//address
Printf (" % p \ n ", & amp; A);
}
Void t2 (int a) {//value transfer
Printf (" % p \ n ", & amp; A);
}
Void t3 (int * a) {//value transfer
Printf (" % p \ n ", & amp; A);
}
Int main (int arg c, const char * argv []) {
Int p=0;
Int & amp; P1=p;
Int * p2=& amp; p;
Printf (" main: % p \ n ", & amp; P);
T1 (p1);
T2 (p);
T3 (p2);
return 0;
}
CodePudding user response:
This is the definition of c function?C can also define functions so?
No reference, c & amp; Is the address, but this is the function definition stage, only void (linklist * p);
Void void inside the c + + f (linklist & amp; P);
This is the reference, and the latter is that it is equivalent to the difference between a hand and the variable passed in the call time, rather than the value of a variable, so function in front of the modified p, can back to function outside; After the latter to modify p values only within the function effectively,