+ 2
What is the value of a3 in the following code: string a1,a2,a3; a1="45" a2="31" a3=a2+a1;
6 ответов
+ 3
Because a1, a2, a3 are strings, the + operator concatenates strings. The result of a2+a1 would be a string with the value of "3145".
+ 2
When using the + operator on strings it simply puts the two strings next to one another. It doesn't care that there are numbers within the string and does not add them together, it just puts one string next to the other.
Instead of using numbers, try this with letters to help see how this works.
when you use this: string a1,a2,a3; a1="ABC" a2="xyz" a3=a2+a1;
the result will be a3="xyzABC"
Inserting numbers into that results in the same logic: string a1,a2,a3; a1="A12" a2="xy3" a3=a2+a1;
the result will be a3="xy3A12"
And as you see, changing to all numbers also results in the same logic: string a1,a2,a3; a1="45" a2="31" a3=a2+a1;
the result will be a3="3145"
+ 1
Can you show me the calculation, Chris. I am still not getting it.
+ 1
Chris can you help me with one more question..
Why is x=1,024 not valid and x=(1,024) valid??
0
Can anybody help me??
0
Need more info on your second question. What is x declared as? What are you using it for - can you provide an example of your code? What are you using a comma for? A decimal place, separator, or something else?