& symbol

Pages: 12345
closed account (1CfG1hU5)
anyhoo, i'm tired, and I don't need mikeyboy for a mommy. am calling & for addresses a reference.

interestingly enough, the & reference is in a reference section here called pointers
http://www.cplusplus.com/doc/tutorial/pointers/

see ya in 20 hrs or less after some shuteye
closed account (1CfG1hU5)
believe it or not, turbo c++ 1 calls the & for addresses a reference.
closed account (1CfG1hU5)
which violations?
am calling & for addresses a reference.

Then the only thing you'll achieve is to confuse and mislead other people who are trying to learn things here.

Is that really what you're trying to do?
Last edited on
am calling & for addresses a reference
refences does not have addresses.
Do you know the meaning of the word context?

int& a; & there is not a address-of operator (which is the correnct name for unary operator &) it is a part of the type. Can you write int +a? Or int -a? No? Well, as you can see it is not an unary operator here.
It is a reference.
http://www.oopweb.com/CPP/Documents/ThinkCScpp/Volume/chap16.htm
do not confuse the "address of" operator with the declaration of a reference

http://msdn.microsoft.com/en-us/library/w7049scy.aspx
Do not confuse reference declarations with use of the address-of operator


Standard wrote:
8.3.2 References [dcl.ref]
1 In a declaration T D where D has either of the forms
& attribute-specifier-seqopt D1
&& attribute-specifier-seqop tD1
and the type of the identifier in the declaration T D1 is “derived-declarator-type-list T,” then the type of the identifier of D is “derived-declarator-type-list reference to T.” The optional attribute-specifier-seq appertains to the reference type. [...]
[ Note: A reference can be thought of as a name of an object. —end note ] A declarator that specifies the type “reference to cv void” is ill-formed.
2 A reference type that is declared using & is called an lvalue reference, and a reference type that is declared using && is called an rvalue reference. Lvalue references and rvalue references are distinct types. Except where explicitly noted, they are semantically equivalent and commonly referred to as references.

Address-of operator wis whole different thing. You cannot have address of temporary. You can bind temporary toa const reference:
1
2
const int& x =  10; //Fine
const int* y = &10; //Error 
Last edited on
closed account (48T7M4Gy)
jt1 has done a great job in helping a fellow traveller in good faith. I think it is better to be constructive than criticize and nitpick even though the OP has probably long gone wishing never to have asked.

http://www.hermetic.ch/cfunlib/ast_amp2.htm
closed account (1CfG1hU5)
i'm saying & is a reference. .
1
2
3
4
5
6
7
8
#include <stdio.h>

int main()
 {
   unsigned int x;
   printf("the address of x is 0x%x", &x);
   return 0;
 }

& used here as address-of operator

need some z's. be able to do more when not so blah.
Last edited on
closed account (1CfG1hU5)
thanks kemort
i'm saying & is a reference. helps display address of variable.

No! In the code you just posted, & does not denote a reference. It's the address-of operator.
Last edited on
closed account (1CfG1hU5)
k

closed account (1CfG1hU5)
have a good morn, bbl
closed account (48T7M4Gy)
i'm saying & is a reference.
jt1

In a declaration, the unary suffix & means ‘‘reference to.’’
Stroustrup

Same-same, or near as dammit to me, that's of course if the context is 'passing-by-reference'. :)
He was talking in the context of unary operator. Not suffix.
closed account (1CfG1hU5)
found a program:

1
2
3
4
5
6
7
8
9
10
11
12
13
#include <stdio.h>

int main(void)
 {
   unsigned int count = 1;
   float salary = 40000.0;
   unsigned long distance = 1234567L;

   printf("Address of count is %x\n", &count);
   printf("Address of salary is %x\n", &salary);
   printf("Address of distance is %x\n", &distance);
   return 0;
 }


bbl
Last edited on
&count address-of operator, not reference.
&salary address-of operator, not reference.
&distance address-of operator, not reference.

closed account (48T7M4Gy)
The key word is not 'suffix' as the adress-of operator '&' can be 'attached' to the type or the variable, where appropriate. Stroustrup is writing in the context of the '&' being a suffix in his code example. Other than that the word has no contextual significance whatsoever. He could have easily said 'prefix' by shifting the position of the '&' in his code example.

In the examples given immediately above the &variableName is a reference to variableName and this is acheived by the prefix, in these cases, by the use of the '&'.

All of this we all know.

I hope this now clears up constructively, the real context of Stroustrup's endeavours.
And what did it change? That reference declaration directly follows type? That address-of operator and reference declarator are two differenct concepts with two different names which usage cannot intesect?

He could have easily said 'prefix' by shifting the position of the '&' in his code example.
Spaces do not matter. Even if he shifted position he would talk about suffix anyway.

Stroustrup preferes to think of reference declaration as part of type (which it actually is) and talks about it like that.
Some people likes to think that it is part of variable declaration (because of one of the ugliest C leftovers).
closed account (48T7M4Gy)
Pegasus - the eternal nag.
@MikeyBoy and @MiiNiPaa,

I agree with you completely, but there is some history of calling addresses "references". Our own tutorial (http://www.cplusplus.com/doc/tutorial/pointers/) refers to '&' as the "Reference operator". That should probably be cleaned up.

@jt1,

believe it or not, turbo c++ 1 calls the & for addresses a reference.


Back when I learned C (about 20 some years ago), when we had functions that took pointers as arguments, the instructor referred to that as pass by reference. The pointer was an address of (or "reference" to) a variable or struct, and could be manipulated by the function being called. Turbo C++ 1 came out around that time, which was pre-standard. Calling pointers "references" would have been understandable (to some extent) to programmers familiar with C pointers.

When C++ became more robust, the term reference took on a whole new meaning. A C++ reference is completely distinct from a pointer. When using the term "reference" to describe a pointer (address), you completely dismiss the C++ reference construct (and you don't even seem to be aware of it). While some refer to the "address-of operator" as the "reference operator", the operator returns an address, not a reference. That terminology needs to be stamped out, and old, pre-standard compilers don't make that any easier.

Turbo C++ 1 is a VERY old compiler and should be retired by now. Find yourself a new compiler and learn some of the new features of standard C++.

closed account (48T7M4Gy)
A reference is similar to a pointer, except that you don’t need to use a prefix * to access the value referred to by the reference. Also, a reference cannot be made to refer to a different object after its initialization.
Pages: 12345