+ 2

String operation

Cans someone help me with why a string addedto a number gives an error? Eg: ‘5’ + 6

1st Jul 2019, 6:52 AM
Aru
2 odpowiedzi
+ 3
In most programming languages, you can only do operarions on two pieces of data that are the same type. One exception is when it is possible to implicitly type-cast one of the operands, for example when you add an integer and a float: 5 + 6.0 = 11.0 Strings are not numeric types, so most programming languages will freak out if you try to add a number to a string :)
1st Jul 2019, 7:00 AM
Tibor Santa
Tibor Santa - avatar
+ 3
thank you so much:)
1st Jul 2019, 10:14 AM
Aru