J
johnnash
I saw this particular piece of code in a book which basically adds two
vectors and produces the sum
Vector *VectorAdd( Vector *a, Vector *b, Vector *c)
{
c->x = a->x + b->x ;
c->y = a->y + b->y ;
c->z = a->z + b->z;
return(c);
}
Now my doubt about this code is why did the author decide to return
the address of c ? Is it not true that when we pass values by
reference, then there is no need to return anything as changes are
automatically reflected at the address of the variable ?
vectors and produces the sum
Vector *VectorAdd( Vector *a, Vector *b, Vector *c)
{
c->x = a->x + b->x ;
c->y = a->y + b->y ;
c->z = a->z + b->z;
return(c);
}
Now my doubt about this code is why did the author decide to return
the address of c ? Is it not true that when we pass values by
reference, then there is no need to return anything as changes are
automatically reflected at the address of the variable ?