The output of the first piece of code is 14 because the value of variable ival (referred to by ref) is set to the value of ival2 (which is 14). A reference can only be set once, upon construction (line 4). Afterwards, any operation on the reference is exactly as if it was the variable it refers to. It is essentially like as if you just change the name of the variable. If you print out the value of ival too on line 6, you would also get 14.

>>1 more thing- do references occupy seperate spaces in memory like pointers ?
That depends on the case. In the example you posted, no, because the compiler is intelligent enough to know that ref is ival and there is no point in creating a "pointer" to ival (sort of encapsulated in the underlying implementation of the reference type). But under other circumstances (like getting a variable passed by reference to a function) it is more likely that the compiler will implement the reference with an underlying "pointer", but that depends how complex (inline or not, and the memory pattern on the stack) the situation is and how clever your compiler is.

For the second code snippet, I wasn't sure myself what a sizeof on a reference would output. So to feed my curiosity I tested this:

>1 more thing- do references occupy seperate spaces in memory like pointers ?
In general, it's safe to assume that references do take up space under the hood, because otherwise how would the compiler maintain the relationship of reference->referent? Officially, it's unspecified by the language definition, which gives compilers leeway to optimize away references in certain cases. Your program, for example, could potentially be optimized as such:

>printf("%p %p\n", &ival, &ref);
This is a silly test to see if references occupy memory. Obviously due to the semantics of references, you're taking the address of the referent rather than the reference. I believe you'll find that Visual Studio uses a pointer internally if you include assembler output in your build.

Hi. so this is actually a continuation from another question of mine[Here](https://www.daniweb.com/programming/software-development/threads/506795/dynamically-add-values-into-datagridview-cell-from-listbox-vb2010) but i was advised to start a new thread as the original question …

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 ...

Write a C program that should create a 10 element array of random integers (0 to 9). The program should total all of the numbers in the odd positions of the array and compare them with the total of the numbers in the even positions of the array and indicate ...