About Casting, at least in the granddaddy of programming languages, C, just meant interpreting the value of a variable as if it was a different kind of variable. Important detail is that variables are actually just memory locations and the number of bytes that conform it. So if you have a variable x of type string that holds the letter A, and a variable y also of type string with the letter B, if you do
x+y
You get ‘AB’. But if you cast the variables like this:
(int)x + (int)y
You get 131
To put it in words as you asked, you are saying “please add the values located at memory locations x and y, but treat the values found there as if they were numbers, and not the ASCII codes for letters (which is what I had originally told you was there)”.
It’s been almost 30 years since the last time I actually used this, so I might be recalling something wrong.
About Casting, at least in the granddaddy of programming languages, C, just meant interpreting the value of a variable as if it was a different kind of variable. Important detail is that variables are actually just memory locations and the number of bytes that conform it. So if you have a variable x of type string that holds the letter A, and a variable y also of type string with the letter B, if you do
x+y
You get ‘AB’. But if you cast the variables like this:
(int)x + (int)y
You get 131
To put it in words as you asked, you are saying “please add the values located at memory locations x and y, but treat the values found there as if they were numbers, and not the ASCII codes for letters (which is what I had originally told you was there)”.
It’s been almost 30 years since the last time I actually used this, so I might be recalling something wrong.