flipnSink95
Member
|
& 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 |
|
Driklyn
Member
|
RE: & In arguments and variables
|
|
11-30-2010 06:25 PM |
|
Dandruff
Member
|
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 |
|
Chris
Member
|
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 |
|