I have seen C function calls that deal with *param1 and ¶m2
func1(*param1);
func2(¶m2);
I know the * and & has to with pointers. So what's purpose doing with these two different ways? Any advantage of each one?
func1(*param1);
In this case, you are passing the contents of the address to which the pointer param1 points to the function func1.
func2(¶m2);
In this case, you are passing the address of param2 to the function func2.
In essence, the second creates a new pointer (i.e., "look over there!") and the first tells you what the pointer is pointing at (i.e., "what's in this box?").
To drive the point home, here is a practically useless example:
int x = 1234; /* an example value */
int *y = &x; /* The pointer y now points at x (or the memory location in which x resides). */
int z = *y; /* z is now = 1234 - it looked at what y was pointing at and took that value. */
int w = *(&x); /* w is now = 1234 - I created a temporary pointer and then immediately dereferenced it. */
Also, note that int *y pointer definition: the star has a different meaning during variable definitions. It is used to define a pointer rather than dereference one. A bit confusing for a novice admittedly....
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With