thank you very much for the explanation of * and &.
unfortunately, it is going to take me some time to understand this pointer
business. is it true that C has both pass by value and pass by reference, but
C++ has only pass by reference. In 'pass by value' the value does not change
when passed from an actual parameter to a formal parameter and with pass by
reference in C++ the value changes
I work mainly on C++, but I use C because I think C is easier to
understand. sometimes I get confused with the >> and <<. The >> is for cin
which gets printed to the screen and << which is cout, the input
thanks
bob
Thomas Hruska <[EMAIL PROTECTED]> wrote: Robert
Ryan wrote:
> what I am trying to figure out: call by value - call by reference - calling
> a function or to call a function.
> to call by value or call by reference
do you use a pointer * or do you use &
Depends. In C, you can only do:
Swap(&a, &b);
void Swap(int *x, int *y)
In C++, you can let the compiler do the same thing much more easily:
Swap(a, b);
void Swap(int &x, int &y)
Produces the same effect, but the latter is safer to use...it is harder
to pass in an invalid pointer.
> I think 'value' is the copy of and 'reference' is the address of
> bob
Swap(a, b);
void Swap(int x, int y)
Will copy a and b to x and y respectively.
Swap(&a, &b);
void Swap(int *x, int *y)
Passes the address-of a and b to x and y respectively. This grants x
and y access to the location of the values that a and b point to.
Swap(a, b);
void Swap(int &x, int &y)
{
int t = x;
x = y;
y = t;
}
The compiler passes the address-of a and b but pointer access
(dereferencing) is completely transparent even within the Swap()
function itself.
--
Thomas Hruska
CubicleSoft President
Ph: 517-803-4197
*NEW* MyTaskFocus 1.1
Get on task. Stay on task.
http://www.CubicleSoft.com/MyTaskFocus/
---------------------------------
Looking for last minute shopping deals? Find them fast with Yahoo! Search.
[Non-text portions of this message have been removed]