I have seen something in this form:
void function( A_struct &var ) {
var.field0 = 0;
// ...
}
Since there is &
before var
, I thought that var
is a pointer. But in the body, instead of writing var->field0
, var.field0
is written. So, my questions are:
Isn't var
a pointer?
What is the difference between writing A_struct &var
and A_struct *var
in function parameter?
Your question is actually related to C++
void function(A_struct &var)
is not valid for C
because in C
it is used to get an address of a variable. In C++
it is a type of variable which is known as reference
. You can see an example of it in here
void function(A_struct *var)
is allowed in C
and C++
, because is a pointer which holds the address of A_struct
type variable's address.