Understanding Arrays

I recently used some variable Arrays in a script when i noticed the following behaviour:

having defined some variables

VarM1, VarM2 : double

then i put them into an Array

VarAr : double Array = [VarM1, VarM2]

i expected that when i wrote

VarM1 = 0.5

then the according array index VarAr[0] would contain the same value, because in my variables definition i used this variable VarM1 as the item [0] of the Array.
I thought that VarAr[0] and VarM1 would always have the same content and only the ā€œaddressingā€ would be a diffrent oneā€¦ but as it turned out, the variable VarM1 and the content of the Array VarAr[0] are two completely diffrent things which, during run time, donā€™t have any relationship anymore.

On my search for an answer i found this statement from @dhj

Which would perfectly explain the described behaviourā€¦
(But this still is some kind of confusing for me)

That statement assigns the value of ā€˜VarM1ā€™ to VarAr[0] and the value of VarM2 to VarAr[1]. It is not assigning the addresses of those variables ā€“ remember that the type of that array is double so the array expects double values at every index.

Consider the following as an analogy

VarAr : double Array = [42, 65]

You could not then write

42 = 0.5

Incidentally, since you didnā€™t initialize those variable, the actual values in the first two entries of VarAr will be random

2 Likes

Makes perfect senseā€¦ thanks for the clarification. :+1: