0

When the actual data type of a variable will be decided?
For ex:
x=10 here x will hold integer
x="Hello" here x will hold string

My basic question is msgbox "2"+"3" is 23 because these are strings and + is for concatenation so the result is 23

Then how the result of msgbox "2"*"3" becomes 6? where the string will be converted to integers and returns 6

Bernhard Barker
  • 54,589
  • 14
  • 104
  • 138
Uday
  • 1,433
  • 10
  • 36
  • 57

1 Answers1

0

If you are talking about using Visual Basic (you have not specified a language) then here is what I believe is happening:

The MsgBox function is expecting a and Object to turn into a String. (or at least it is trying to convert a String before it is displayed). Since "+" is a legit operator for concatenation, the first example can be directly converted to a String and returned.

In the second example, the asterisk is not a legit String operator, so it then has to attempt to convert your String segments into Integers. It does, then multiplies them, then the MsgBox converts the numerical expression back into a String and displays it.

Bull Durham
  • 184
  • 1
  • 6