A reference variable such as "p" becomes equivalent to, or a synonym for, "a" and you can use the variable names interchangeably without any special operations (although it's not really recommended for maintainability reasons). If you change "p" you change "a" and vice versa.
Your syntax isn't correct, but a pointer variable such as "q" is not equivalent to "a". It stores the address of "a" rather than the value of "a". As a result, you need a special operator to access the value that is "pointed to" by the variable "q". If you change "q", it stores a different address and no longer points to "a" and the variable "a" remains unchanged.
ok now i understand that reference is like another name for a variable......
then wat could be said "when function return type is a reference" ??
wat does that mean and that time wat could be said about the scope of the reference variable??
functions return a reference so that there is less overhead in the function return. whatever value you store the return into will hold that value and it doesn't matter that the variable that was returned goes out of scope.
// non reference return
int a = 20;
// reference return
int & foo()
int a = 20;
as you can see there is no difference between the code except how the return value is returned. it will still get assigned to the variable you have receiving the return.
>>it doesn't matter that the variable that was returned goes out of scope.
Of course it does indeed matter. Returning a reference as in your second code snippet is very similar to returning a pointer like this:
int a = 10;
Both the reference you posted and the pointer I posted above are wrong and will most likely cause problems for the calling function.
I am working creating a fully encapsulated, homogeneous singly linked data structure. The Listing class and SinglyLinkedList class that are part of the whole application compile fine, but the problem ...