Mail Archives: djgpp/2003/08/28/19:45:41
Hello.
Martin Stromberg wrote:
>
> DJ Delorie (dj AT delorie DOT com) wrote:
> : > From what I can grasp, the asterisk symbol means the same thing.
> : > Though I have yet to really grasp the proper place(s) and form(s)
> : > for its usage.
>
> : Nope, asterisk is the inverse of ampersand. Ampersand takes the
> : address of something, converting values into pointers that point to
> : those values. Asterisks dereference pointers, turning pointers into
> : the values they point to.
>
> Except when you declare/define variables and functions. Then * takes
> the place where newbies would expect &.
>
> Then comes C++ where & is allowed in declarations/definitions too
> (with some semantics I've never bothered to look up; I don't do C++).
& is used to indicate that a variable is passed by reference in
declarations/definitions in C++. E.g.:
---Start test.cpp---
#include <cstdio>
#include <cstdlib>
using namespace std;
void
blargh (int& ref)
{
ref = 12;
}
int
main (void)
{
int a = 5;
blargh(a);
printf("%d\n", a);
return EXIT_SUCCESS;
}
---End test.cpp---
No idea if that will compile. But if it does, it should print 12 when it runs.
blargh modifies the int passed by reference.
I like C++'s Standard Template Library (STL) - type-safe generic container
classes. Saves you having to do generic list classes with macros in C, which
is just horrible. (I strongly dislike C macros most of the time.)
Bye, Rich =]
--
Richard Dawe [ http://www.phekda.freeserve.co.uk/richdawe/ ]
- Raw text -