Using C Pointers: Step 2
In Step 1 of this series, we showed how much work the compiler has to do to process simple statements like these:
int x;
int y;
x = 5;
y = x;
After the definition (not declaration) of x and y, verbalizing the last statement, we can say: “Find the lvalue (i.e., memory address) of x’s bucket and grab the rvalue inside that bucket. Now get the lvalue of y’s bucket, and take x’s rvalue (i.e., 5) and dump it into y’s bucket located at its lvalue.” Note: “normal” assignment expressions in C involve taking the rvalue of one variable and making it the rvalue of a different variable. That is, assignment statements are usually rvalue to rvalue.
We can illustrate this with . When we defined , assumed the compiler assigns it memory address 1000. When we defined , the compiler assigned memory address 1002. On the Arduino Uno or Nano, integer values are 16-bit numbers, so 2 bytes of memory are allocated for each variable. On a 32-bit processor, each variable would have been assigned 4 bytes of memory. (The compiler doesn’t shows the location in memory (i.e., the lvalue) of the two variables as well as their values (rvalue). Sticking with our bucket analogy discussed in my previous column, the variables are depicted as buckets residing in memory.