About Store Forum Documentation Contact
Donations:
309$/mo



Post Reply 
& In arguments and variables
Author Message
flipnSink95 Offline
Member

Post: #1
& In arguments and variables
Hi, I'm new to C++ and I've been noticing & in variables and arguments and I was wondering what it's purpose is. Thank you.

Wait I think I remember it's a pointer, but can someone explain what makes it different?
(This post was last modified: 11-30-2010 05:38 PM by flipnSink95.)
11-30-2010 05:34 PM
Find all posts by this user Quote this message in a reply
Driklyn Offline
Member

Post: #2
RE: & In arguments and variables
11-30-2010 06:25 PM
Find all posts by this user Quote this message in a reply
Dandruff Offline
Member

Post: #3
RE: & In arguments and variables
If the ampersand is before a variable declaration then it's a good bet that that variable is a pointer. If you see && in ifs whiles etc it is called a logical and operator.

Etc: if(hot&&sunny)blahblah;
blahblah would only execute if hot and sunny are both true.
12-01-2010 01:19 AM
Find all posts by this user Quote this message in a reply
Dynad Offline
Member

Post: #4
RE: & In arguments and variables
If you see a pointer value '*' it can be NULL and the pointer reference '&' cannot be NULL. So there is a big difference smile

There is always evil somewhere, you just have to look for it properly.
12-01-2010 01:32 AM
Visit this user's website Find all posts by this user Quote this message in a reply
Chris Offline
Member

Post: #5
RE: & In arguments and variables
It's good coding practice to use references as much as possible; only using pointers when you have to; e.g. in the scenario of reseating (assigning the pointer to another object which isn't the referent).

To summarise references act like they are the referent - which allows you to visualise the problem with a more natural mapping. In this sense they encourage good modern OO-practice. Pointers, however, can sometimes hide the problem; having said that a lot of old-school programmers still prefer them as are very used to pointers.
12-01-2010 01:49 AM
Find all posts by this user Quote this message in a reply
Post Reply