+ 2

What is the value of a3 in the following code: string a1,a2,a3; a1="45" a2="31" a3=a2+a1;

27th Sep 2016, 5:51 PM
Devansh Kaushik
Devansh Kaushik - avatar
6 Answers
+ 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".
27th Sep 2016, 6:39 PM
Chris G
Chris G - avatar
+ 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"
28th Sep 2016, 12:14 PM
Chris G
Chris G - avatar
+ 1
Can you show me the calculation, Chris. I am still not getting it.
28th Sep 2016, 5:12 AM
Devansh Kaushik
Devansh Kaushik - avatar
+ 1
Chris can you help me with one more question.. Why is x=1,024 not valid and x=(1,024) valid??
28th Sep 2016, 2:22 PM
Devansh Kaushik
Devansh Kaushik - avatar
0
Can anybody help me??
28th Sep 2016, 7:39 AM
Devansh Kaushik
Devansh Kaushik - avatar
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?
28th Sep 2016, 7:11 PM
Chris G
Chris G - avatar