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.
Need some help with this Array. I am trying to get the sum of the even numbers and the sum of the odd numbers using a for each loop. I know the answers to what I am trying to achive are sum of even = 84 and the sum of ...
I have a 2d matrix with dimension (3, n) called A, I want to calculate the normalization and cross product of two arrays (b,z) (see the code please) for each column (for the first column, then the second one and so on).
the function that I created to find the ...