+ 2

How does a program know to add two values when '+' sign is put in between them?

int a=2;int b=3; a+b= int c; then c is 5 how does a program identify the operator and does the function related to that sign?

4th Mar 2017, 5:32 AM
Yesha Krish
Yesha Krish - avatar
5 ответов
+ 15
a and b both are integer here not strings. That's why '+' sign add the two values instead of concating them. a="2"; b="3"; c=a+b; // c=23 because a and b both are strings here.
4th Mar 2017, 5:45 AM
Siddharth Saraf
+ 9
One more thing, these things are also common in PHP and JavaScript
13th Mar 2017, 3:48 PM
Siddharth Saraf
+ 2
For compiled program : they are transformed in binary files so the + is changed by the binary message of the addition for the processor. For interpreted programs : quit the same but it is the interpreter which read the + that run its functionality which was transformed in the binary message for addition.
4th Mar 2017, 6:46 AM
Baptiste E. Prunier
Baptiste E. Prunier - avatar
+ 1
thanks for correcting my mistake
4th Mar 2017, 5:47 AM
Yesha Krish
Yesha Krish - avatar
0
what if both are integers?
4th Mar 2017, 5:46 AM
Yesha Krish
Yesha Krish - avatar