delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2003/08/28/19:45:41

From: Richard Dawe <rich AT phekda DOT freeserve DOT co DOT uk>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Simple program. Strange results.
Date: Fri, 29 Aug 2003 00:27:16 +0100
Lines: 57
Message-ID: <3F4E8FD4.AD6096D8@phekda.freeserve.co.uk>
References: <HfZ2b.3213$cQ1 DOT 755278 AT kent DOT svc DOT tds DOT net> <hO%2b.16285$8i2 DOT 341 AT newsread2 DOT news DOT atl DOT earthlink DOT net> <tHc3b.3480$cQ1 DOT 829301 AT kent DOT svc DOT tds DOT net> <200308280125 DOT h7S1PFP5020856 AT envy DOT delorie DOT com> <bika4j$nbn$1 AT antares DOT lu DOT erisoft DOT se>
NNTP-Posting-Host: 62.137.7.3
Mime-Version: 1.0
X-Trace: news7.svr.pol.co.uk 1062113597 13177 62.137.7.3 (28 Aug 2003 23:33:17 GMT)
NNTP-Posting-Date: 28 Aug 2003 23:33:17 GMT
X-Complaints-To: abuse AT theplanet DOT net
X-Mailer: Mozilla 4.77 [en] (X11; U; Linux 2.2.23 i586)
X-Accept-Language: de,fr
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

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 -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019