Guys 'm back. Yeh I know, I just put a lot of bullcrap here on my hompage,
but hey, it's better than nothing ;). Last couple of hours I was learning for school
and when I was done, I continued learning c++ with the 'C++ for DUMMIES' ebook
(I downloaded it as a PDF-file). So the last thing I learned was a bit about pointers,
that they are 'variables that contain the address of other variables' and so forth.
When I read further, I came to a nice thing about functions. As you all know (at least
the programmers of you there), that you can call a function by Value or by Reference.
By Value
Simple explanation: When you call a function by value, you only pass the value of the variable.
example:
int a, b, c;
a = 2;
b = 3;
c = func(a, b);
When you see this snipped of code, de function dose something with the values of a and b and returns a value to c.
So only the values are messed up, not the variables themselves.
By Reference
Simple explanation: When you call a function by reference the addresses of the variables are passed trough
the functions, so when the function does something with those adresses (adding some stuff, substracting stuff etc.)
the variables are also affected.
example:
int a, b;
a = 2;
b = 3;
swap(&a, &b);
Whis snipped of code passes the adresses of those two variables (a and b) trough the function swap. When those
adressen have landed there, the function can start doing some stuff with it. After several statements, the function terminates
(because there are no statements left, so simple is it ;) and main() takes over. BUT! When the swap did something
to variable a, like adding 5, the variable now (in the main-function) contains 7! Exactly the same happens to b, when swap
did some substraction to b, like b = b - 3;, b now contains 0!
I hope you guys all learned something today, I did (some refreshing ;). See you all soon!
cheers, Nick