Quote:
In the function "void foo(const int)", what does the const do? I get how it is usefull if the value is passed as a reference, but when its not i dont understand what the const do.
It serves as a reminder to the implementer of foo() that the parameter is not to be modified. To the caller it does not matter.
Quote:
Is there a difference between void foo(int *a) and void foo(int &a)?
Of course. For the former a is a pointer to an int, for the latter a is an int reference.
Quote:
At university, they teach us to always make all class variables private. Is this really a good idea? I see that is is useful is some cases (say, addMoney() to change the balance a bank account class).
They probably also talked about encapsulation and data hiding. Look up your notes for these concepts. That said, in some cases we could have a POD struct consisting entirely of public member variables. This would serve purely as a way of grouping some data.
Quote:
How can you make a function that turns 1 into 0 and 0 into 1? Without using if statements.
With mathematics ;)