Possible Duplicate:
Why use pointers?
I know what the C++ & does. but what can it be used for?
Possible Duplicate:
Why use pointers?
I know what the C++ & does. but what can it be used for?
&
is used to pass address of arguments (pointer) to function, when it's used at calling site.&
is used to pass arguments by reference to function, when it's used in function parameter list.&
is bitwise AND
. e.g. (a & b)
&
is used in logical AND
. In this case, two &
make logical AND
. e.g (a && b)
.Many functions in the STL or other commonly available libraries requires a pointer to an object (not the object itself). Also, many time you'll want to pass pointers. When you need that, the &
operator allows you to get a pointer to any object you have access to.
Browse through the boost
libraries and find some. One example:
template<class Y> explicit shared_ptr(Y * p);
To pass in a pointer to a Y
you'd have to use the &
operator.
Furthermore, your profile says you're into 3-d games. Almost every C++ 3d library I know of uses pointers to arrays of floats or ints to manipulate everything. You need the &
operator to pass in the pointers to those arrays.